/** * Like create_temp_file() but returns an open file stream to the * created file. It's up to the caller to close returned stream. */ FILE* open_temp_file(TALLOC_CTX *context, const char *prefix) { char *name; FILE *file; int fd; name = create_temp_name(context, prefix); if (name == NULL) return NULL; fd = mkstemp(name); if (fd < 0) goto error; talloc_set_destructor(name, remove_temp_file); file = fdopen(fd, "w"); if (file == NULL) goto error; return file; error: if (fd >= 0) close(fd); note(NULL, ERROR, SYSTEM, "can't create temporary file"); return NULL; }
/** * Like create_temp_file() but returns an open file stream to the * created file. It's up to the caller to close returned stream. */ FILE* open_temp_file(TALLOC_CTX *context, const char *prefix) { char *name; FILE *file; int fd; name = create_temp_name(context, prefix); if (name == NULL) return NULL; fd = mkstemp(name); if (fd < 0) goto error; talloc_set_destructor(name, remove_temp_file); file = fdopen(fd, "w"); if (file == NULL) goto error; return file; error: if (fd >= 0) close(fd); note(NULL, ERROR, SYSTEM, "can't create temporary file"); note(NULL, INFO, USER, "Please set PROOT_TMP_DIR env. variable " "to an alternate location (with write permission)."); return NULL; }
/** * Create a directory that will be automatically removed either on * PRoot termination if @context is NULL, or once its path name * (attached to @context) is freed. This function returns NULL on * error, otherwise the absolute path name to the created directory * (@prefix-ed). */ const char *create_temp_directory(TALLOC_CTX *context, const char *prefix) { char *name; name = create_temp_name(context, prefix); if (name == NULL) return NULL; name = mkdtemp(name); if (name == NULL) { note(NULL, ERROR, SYSTEM, "can't create temporary directory"); return NULL; } talloc_set_destructor(name, remove_temp_directory); return name; }
/** * Create a file that will be automatically removed either on PRoot * termination if @context is NULL, or once its path name (attached to * @context) is freed. This function returns NULL on error, * otherwise the absolute path name to the created file (@prefix-ed). */ const char *create_temp_file(TALLOC_CTX *context, const char *prefix) { char *name; int fd; name = create_temp_name(context, prefix); if (name == NULL) return NULL; fd = mkstemp(name); if (fd < 0) { note(NULL, ERROR, SYSTEM, "can't create temporary file"); return NULL; } close(fd); talloc_set_destructor(name, remove_temp_file); return name; }
/** * Create a directory that will be automatically removed either on * PRoot termination if @context is NULL, or once its path name * (attached to @context) is freed. This function returns NULL on * error, otherwise the absolute path name to the created directory * (@prefix-ed). */ const char *create_temp_directory(TALLOC_CTX *context, const char *prefix) { char *name; name = create_temp_name(context, prefix); if (name == NULL) return NULL; name = mkdtemp(name); if (name == NULL) { note(NULL, ERROR, SYSTEM, "can't create temporary directory"); note(NULL, INFO, USER, "Please set PROOT_TMP_DIR env. variable " "to an alternate location (with write permission)."); return NULL; } talloc_set_destructor(name, remove_temp_directory); return name; }
/** * Translate the pathname of the struct sockaddr_un currently stored * in the @tracee memory at the given @address. See the documentation * of read_sockaddr_un() for the meaning of the @size parameter. * Also, the new address of the translated sockaddr_un is put in the * @address parameter. This function returns -errno if an error * occurred, otherwise 0. */ int translate_socketcall_enter(Tracee *tracee, word_t *address, int size) { struct sockaddr_un sockaddr; char user_path[PATH_MAX]; char host_path[PATH_MAX]; int status; if (*address == 0) return 0; status = read_sockaddr_un(tracee, &sockaddr, sizeof(sockaddr), user_path, *address, size); if (status <= 0) return status; status = translate_path(tracee, host_path, AT_FDCWD, user_path, true); if (status < 0) return status; /* Be careful: sun_path doesn't have to be null-terminated. */ if (strlen(host_path) > sizeof_path) { char *shorter_host_path; Binding *binding; /* The translated path is too long to fit the sun_path * array, so let's bind it to a shorter path. */ shorter_host_path = create_temp_name(tracee->ctx, "proot"); if (shorter_host_path == NULL || strlen(shorter_host_path) > sizeof_path) return -EINVAL; (void) mktemp(shorter_host_path); if (strlen(shorter_host_path) > sizeof_path) return -EINVAL; /* Ensure the guest path of this new binding is * canonicalized, as it is always assumed. */ strcpy(user_path, host_path); status = detranslate_path(tracee, user_path, NULL); if (status < 0) return -EINVAL; /* Bing the guest path to a shorter host path. */ binding = insort_binding3(tracee, tracee->ctx, shorter_host_path, user_path); if (binding == NULL) return -EINVAL; /* This temporary file (shorter_host_path) will be removed once the * binding is destroyed. */ talloc_reparent(tracee->ctx, binding, shorter_host_path); /* Let's use this shorter path now. */ strcpy(host_path, shorter_host_path); } strncpy(sockaddr.sun_path, host_path, sizeof_path); /* Push the updated sockaddr to a newly allocated space. */ *address = alloc_mem(tracee, sizeof(sockaddr)); if (*address == 0) return -EFAULT; status = write_data(tracee, *address, &sockaddr, sizeof(sockaddr)); if (status < 0) return status; return 1; }
P2 (PUBLIC pascal trap, OSErr, FSpExchangeFiles, FSSpecPtr, src, FSSpecPtr, dst) { #if 0 save_fcb_info_t *src_fcb_info, *dst_fcb_info; OSErr retval; src_fcb_info = get_fcb_info (src); dst_fcb_info = get_fcb_info (dst); retval = exchange_forks (src, dst, datafork); if (retval == noErr) { retval = exchange_forks (src, dst, resourcefork); if (retval != noErr) exchange_forks (src, dst, datafork); /* try to put things back together */ } if (retval == noErr) exchange_fcbs (src, src_fcb_info, dst, dst_fcb_info); else { restore_fcb (src_fcb_info); restore_fcb (dst_fcb_info); } release_fcb_info (src_fcb_info); release_fcb_info (dst_fcb_info); return retval; #else OSErr retval; warning_unimplemented ("poorly implemented"); if (src->vRefNum != dst->vRefNum) retval = diffVolErr; else if (ROMlib_creator != TICK("PAUP") || src->parID != dst->parID) retval = wrgVolTypeErr; else { /* Evil hack to get PAUP to work -- doesn't bother adjusting FCBs */ FSSpec tmp_spec; int i; i = 0; tmp_spec = *dst; do { create_temp_name (tmp_spec.name, i++); retval = FSpRename (dst, tmp_spec.name); } while (retval == dupFNErr); if (retval == noErr) { retval = FSpRename (src, dst->name); if (retval != noErr) FSpRename (&tmp_spec, dst->name); else { retval = FSpRename (&tmp_spec, src->name); if (retval != noErr) { FSpRename (dst, src->name); FSpRename (&tmp_spec, dst->name); } } } } return retval; #endif }
static void create_file_names(void) { register int len; register char *defines_suffix; register char *prefix; prefix = NULL; defines_suffix = DEFINES_SUFFIX; /* compute the file_prefix from the user provided output_file_name */ if (output_file_name != 0) { defines_suffix = ".h"; if (!(prefix = is_suffix(output_file_name, ".cpp"))) prefix = is_suffix(output_file_name, ""); } if (prefix != NULL) { len = prefix - output_file_name; file_prefix = (char *)MALLOC(len + 1); if (file_prefix == 0) no_space(); strncpy(file_prefix, output_file_name, len)[len] = 0; } else len = strlen(file_prefix); /* if "-o filename" was not given */ if (output_file_name == 0) { oflag = 1; CREATE_FILE_NAME(output_file_name, OUTPUT_SUFFIX); } if (rflag) { CREATE_FILE_NAME(code_file_name, CODE_SUFFIX); } else code_file_name = output_file_name; if (dflag) { CREATE_FILE_NAME(defines_file_name, defines_suffix); } if (vflag) { CREATE_FILE_NAME(verbose_file_name, VERBOSE_SUFFIX); } if (gflag) { CREATE_FILE_NAME(graph_file_name, GRAPH_SUFFIX); } if (prefix != NULL) { FREE(file_prefix); } create_temp_name(&text_file_name, output_file_name, ".byacc.text"); create_temp_name(&union_file_name, output_file_name, ".byacc.union"); create_temp_name(&action_file_name, output_file_name, ".byacc.action"); }