iree/base/internal/dynamic_library_posix.c
static iree_status_t iree_dynamic_library_make_temp_file_path(
    const char* prefix, const char* extension, iree_allocator_t allocator,
    char** out_file_path) {
  // Query the 'TMPDIR' environment variable to allow users to override the
  // path.
  const char* tmpdir = getenv("TMPDIR");
  if (!tmpdir) {
#ifdef __ANDROID__
    // Support running Android command-line programs both as regular shell user
    // and as root. For the latter, TMPDIR is not defined by default.
    tmpdir = "/data/local/tmp";
#else
    tmpdir = "/tmp";
#endif  // __ANDROID__
  }

  // Stamp in a unique file name (replacing XXXXXX in the string).
  char temp_path[512];
  if (snprintf(temp_path, sizeof(temp_path), "%s/iree_dylib_XXXXXX", tmpdir) >=
      sizeof(temp_path)) {
    // NOTE: we could dynamically allocate things, but didn't seem worth it.
    return iree_make_status(
        IREE_STATUS_INVALID_ARGUMENT,
        "TMPDIR name too long (>%zu chars); keep it reasonable",
        sizeof(temp_path));
  }
  int fd = mkstemp(temp_path);
  if (fd < 0) {
    return iree_make_status(iree_status_code_from_errno(errno),
                            "unable to mkstemp file");
  }

  // Allocate storage for the full file path and format it in.
  int file_path_length =
      snprintf(NULL, 0, "%s_%s.%s", temp_path, prefix, extension);
  if (file_path_length < 0) {
    return iree_make_status(IREE_STATUS_INVALID_ARGUMENT,
                            "unable to form temp path string");
  }
  IREE_RETURN_IF_ERROR(iree_allocator_malloc(
      allocator, file_path_length + /*NUL=*/1, (void**)out_file_path));
  snprintf(*out_file_path, file_path_length + /*NUL=*/1, "%s_%s.%s", temp_path,
           prefix, extension);

  // Canonicalize away any double path separators.
  iree_file_path_canonicalize(*out_file_path, file_path_length);

  return iree_ok_status();
}
// Allocate a new string from |allocator| returned in |out_file_path| containing
// a path to a unique file on the filesystem.
Allocate a new string from |allocator| returned in |out_file_path| containing
a path to a unique file on the filesystem.
Allocate a new string from |allocator| returned in |out_file_path| containing a path to a unique file on the filesystem .
static iree_status_t iree_dynamic_library_make_temp_file_path(
    const char* prefix, const char* extension, iree_allocator_t allocator,
    char** out_file_path) {
  const char* tmpdir = getenv("TMPDIR");
  if (!tmpdir) {
#ifdef __ANDROID__
    tmpdir = "/data/local/tmp";
#else
    tmpdir = "/tmp";
#endif  
  }
  char temp_path[512];
  if (snprintf(temp_path, sizeof(temp_path), "%s/iree_dylib_XXXXXX", tmpdir) >=
      sizeof(temp_path)) {
    return iree_make_status(
        IREE_STATUS_INVALID_ARGUMENT,
        "TMPDIR name too long (>%zu chars); keep it reasonable",
        sizeof(temp_path));
  }
  int fd = mkstemp(temp_path);
  if (fd < 0) {
    return iree_make_status(iree_status_code_from_errno(errno),
                            "unable to mkstemp file");
  }
  int file_path_length =
      snprintf(NULL, 0, "%s_%s.%s", temp_path, prefix, extension);
  if (file_path_length < 0) {
    return iree_make_status(IREE_STATUS_INVALID_ARGUMENT,
                            "unable to form temp path string");
  }
  IREE_RETURN_IF_ERROR(iree_allocator_malloc(
      allocator, file_path_length + 1, (void**)out_file_path));
  snprintf(*out_file_path, file_path_length + 1, "%s_%s.%s", temp_path,
           prefix, extension);
  iree_file_path_canonicalize(*out_file_path, file_path_length);
  return iree_ok_status();
}
static iree_status_t iree_dynamic_library_make_temp_file_path ( const char * prefix , const char * extension , iree_allocator_t allocator , char * * out_file_path ) { const char * tmpdir = getenv ( " " ) ; if ( ! tmpdir ) { #ifdef __ANDROID__ tmpdir = " " ; #else tmpdir = " " ; #endif } char temp_path [ 512 ] ; if ( snprintf ( temp_path , sizeof ( temp_path ) , " " , tmpdir ) >= sizeof ( temp_path ) ) { return iree_make_status ( IREE_STATUS_INVALID_ARGUMENT , " " , sizeof ( temp_path ) ) ; } int fd = mkstemp ( temp_path ) ; if ( fd < 0 ) { return iree_make_status ( iree_status_code_from_errno ( errno ) , " " ) ; } int file_path_length = snprintf ( NULL , 0 , " " , temp_path , prefix , extension ) ; if ( file_path_length < 0 ) { return iree_make_status ( IREE_STATUS_INVALID_ARGUMENT , " " ) ; } IREE_RETURN_IF_ERROR ( iree_allocator_malloc ( allocator , file_path_length + 1 , ( void * * ) out_file_path ) ) ; snprintf ( * out_file_path , file_path_length + 1 , " " , temp_path , prefix , extension ) ; iree_file_path_canonicalize ( * out_file_path , file_path_length ) ; return iree_ok_status ( ) ; }
Allocate a new string from |allocator| returned in |out_file_path| containing
a path to a unique file on the filesystem.
Allocate a new string from |allocator| returned in |out_file_path| containing a path to a unique file on the filesystem .
// Query the 'TMPDIR' environment variable to allow users to override the // path. // Support running Android command-line programs both as regular shell user // and as root. For the latter, TMPDIR is not defined by default. // __ANDROID__ // Stamp in a unique file name (replacing XXXXXX in the string). // NOTE: we could dynamically allocate things, but didn't seem worth it. // Allocate storage for the full file path and format it in. /*NUL=*/ /*NUL=*/ // Canonicalize away any double path separators.