int do_unpack(void) { struct file_header untrusted_hdr; #ifdef HAVE_SYNCFS int cwd_fd; int saved_errno; #endif total_bytes = total_files = 0; /* initialize checksum */ crc32_sum = 0; while (read_all_with_crc(0, &untrusted_hdr, sizeof untrusted_hdr)) { /* check for end of transfer marker */ if (untrusted_hdr.namelen == 0) { errno = 0; break; } total_files++; if (files_limit && total_files > files_limit) do_exit(EDQUOT, untrusted_namebuf); process_one_file(&untrusted_hdr); } #ifdef HAVE_SYNCFS saved_errno = errno; cwd_fd = open(".", O_RDONLY); if (cwd_fd >= 0 && syncfs(cwd_fd) == 0 && close(cwd_fd) == 0) errno = saved_errno; #endif send_status_and_crc(errno, untrusted_namebuf); return errno; }
iERR process_filename(char *pathname, ION_READER_OPTIONS *options) { iENTER; #ifdef WIN OPT_MSG *next, *node, *head = NULL; if (g_debug) { fprintf(stderr, "expanding wildcard %s\n", pathname); } if (strchr(pathname, '*') != NULL || strchr(pathname, '?') != NULL) { head = opt_decode_wildcards(head, pathname); for (node=head; node; node=next) { next = node->next; // because we're going to free it before we get to the loop err = process_one_file(node->msg, options); if (err != IERR_OK) { fprintf(stderr, "WARNING: err [%d: '%s'] processing file '%s'\n", err, ion_error_to_str(err), node->msg); err = IERR_OK; } free(node->msg); free(node); } CHECK(err, "ERROR: processing wildcard expanded files\n"); } else { CHECK( process_one_file(pathname, options), "process the one file"); } #else if (g_debug) { fprintf(stderr, "DON'T expand wildcard %s\n", pathname); } CHECK( process_one_file(pathname, options), "process the one file"); #endif iRETURN; }
int do_unpack(void) { struct file_header untrusted_hdr; total_bytes = total_files = 0; /* initialize checksum */ crc32_sum = 0; while (read_all_with_crc(0, &untrusted_hdr, sizeof untrusted_hdr)) { /* check for end of transfer marker */ if (untrusted_hdr.namelen == 0) { errno = 0; break; } total_files++; if (files_limit && total_files > files_limit) do_exit(EDQUOT, untrusted_namebuf); process_one_file(&untrusted_hdr); } send_status_and_crc(errno, untrusted_namebuf); return errno; }
int main (int argc, char **argv) { int file_index; /* On Mac, fetch a command line. */ #ifdef USE_CCOMMAND argc = ccommand(&argv); #endif #ifdef MSDOS progname = "djpeg"; /* DOS tends to be too verbose about argv[0] */ #else progname = argv[0]; if (progname == NULL || progname[0] == 0) progname = "djpeg"; /* in case C library doesn't provide it */ #endif /* The default maxmem must be computed only once at program startup, * since releasing memory with free() won't give it back to the OS. */ #ifdef FREE_MEM_ESTIMATE default_maxmem = FREE_MEM_ESTIMATE; #else default_maxmem = 0; #endif /* Scan command line, parse switches and locate input file names */ if (argc < 2) usage(); /* nothing on the command line?? */ file_index = 0; while (file_index < argc-1) file_index = process_one_file(argc, argv, file_index); /* All done. */ exit(EXIT_SUCCESS); return 0; /* suppress no-return-value warnings */ }
int main (int argc, char **argv) { GOptionContext *context; GOptionGroup *group; GError* err = NULL; int i; mode_t dir_permissions; setlocale (LC_ALL, ""); context = g_option_context_new (""); g_option_context_add_main_entries (context, options, NULL); group = g_option_group_new ("edit", _("Edition options for desktop file"), _("Show desktop file edition options"), NULL, NULL); g_option_group_add_entries (group, edit_options); g_option_context_add_group (context, group); err = NULL; g_option_context_parse (context, &argc, &argv, &err); if (err != NULL) { g_printerr ("%s\n", err->message); g_printerr (_("Run '%s --help' to see a full list of available command line options.\n"), argv[0]); g_error_free (err); return 1; } if (vendor_name == NULL && g_getenv ("DESKTOP_FILE_VENDOR")) vendor_name = g_strdup (g_getenv ("DESKTOP_FILE_VENDOR")); if (copy_generic_name_to_name && copy_name_to_generic_name) { g_printerr (_("Specifying both --copy-name-to-generic-name and --copy-generic-name-to-name at once doesn't make much sense.\n")); return 1; } if (target_dir == NULL && g_getenv ("DESKTOP_FILE_INSTALL_DIR")) target_dir = g_strdup (g_getenv ("DESKTOP_FILE_INSTALL_DIR")); if (target_dir == NULL) target_dir = g_build_filename (DATADIR, "applications", NULL); /* Create the target directory */ dir_permissions = permissions; /* Add search bit when the target file is readable */ if (permissions & 0400) dir_permissions |= 0100; if (permissions & 0040) dir_permissions |= 0010; if (permissions & 0004) dir_permissions |= 0001; g_mkdir_with_parents (target_dir, dir_permissions); i = 0; while (args && args[i]) { err = NULL; process_one_file (args[i], &err); if (err != NULL) { g_printerr (_("Error on file \"%s\": %s\n"), args[i], err->message); g_error_free (err); return 1; } ++i; } if (i == 0) { g_printerr (_("Must specify one or more desktop files to install\n")); return 1; } g_option_context_free (context); return 0; }
Func_DWARF *SET_fill_func_dwarf(char *name, uint32_t *func_addr, int len, uint32_t off) { int fd; Elf_Cmd cmd; Elf *arf; /* Used for an archive */ Elf *elf; int ret; if (elf_version(EV_CURRENT) == EV_NONE) { fprintf(stderr, "SET dwarf: libelf.a is out of date\n"); return NULL; } fd = open(name, O_RDONLY); if (fd == -1) { fprintf(stderr, "SET dwarf: Cannot open %s\n", name); return NULL; } /* Function DWARF table */ func_dwarf = (Func_DWARF *) malloc(sizeof(Func_DWARF) * len); if (func_dwarf == NULL) { fprintf(stderr, "SET dwarf: No memory space to allocate DWARF table!\n"); close(fd); return NULL; } memset(func_dwarf, 0, sizeof(Func_DWARF) * len); local_func_addr = func_addr; local_func_len = len; local_offset = off; cmd = ELF_C_READ; arf = elf_begin(fd, cmd, NULL); while ((elf = elf_begin(fd, cmd, arf)) != NULL) { Elf32_Ehdr *eh32; eh32 = elf32_getehdr(elf); if (eh32 == NULL) { fprintf(stderr, "SET dwarf: %s is not a 32-bit ELF file\n", name); goto fail; } else { ret = process_one_file(elf); if (ret != 0) goto fail; } cmd = elf_next(elf); elf_end(elf); } elf_end(arf); close(fd); return func_dwarf; fail: elf_end(elf); elf_end(arf); free(func_dwarf); close(fd); return NULL; }
int main (int argc, char **argv) { GOptionContext *context; GOptionGroup *group; GError* err = NULL; int i; int args_len; mode_t dir_permissions; char *basename; setlocale (LC_ALL, ""); basename = g_path_get_basename (argv[0]); if (g_strcmp0 (basename, "desktop-file-edit") == 0) edit_mode = TRUE; g_free (basename); context = g_option_context_new (""); g_option_context_set_summary (context, edit_mode ? _("Edit a desktop file.") : _("Install desktop files.")); g_option_context_add_main_entries (context, main_options, NULL); if (!edit_mode) { group = g_option_group_new ("install", _("Installation options for desktop file"), _("Show desktop file installation options"), NULL, NULL); g_option_group_add_entries (group, install_options); g_option_context_add_group (context, group); } group = g_option_group_new ("edit", _("Edition options for desktop file"), _("Show desktop file edition options"), NULL, NULL); g_option_group_add_entries (group, edit_options); g_option_group_set_parse_hooks (group, NULL, post_parse_edit_options_callback); g_option_context_add_group (context, group); err = NULL; g_option_context_parse (context, &argc, &argv, &err); if (err != NULL) { g_printerr ("%s\n", err->message); g_printerr (_("Run '%s --help' to see a full list of available command line options.\n"), argv[0]); g_error_free (err); return 1; } if (!edit_mode) { if (vendor_name == NULL && g_getenv ("DESKTOP_FILE_VENDOR")) vendor_name = g_strdup (g_getenv ("DESKTOP_FILE_VENDOR")); if (target_dir == NULL && g_getenv ("DESKTOP_FILE_INSTALL_DIR")) target_dir = g_strdup (g_getenv ("DESKTOP_FILE_INSTALL_DIR")); if (target_dir == NULL) { if (g_getenv ("RPM_BUILD_ROOT")) target_dir = g_build_filename (g_getenv ("RPM_BUILD_ROOT"), DATADIR, "applications", NULL); else target_dir = g_build_filename (DATADIR, "applications", NULL); } /* Create the target directory */ dir_permissions = permissions; /* Add search bit when the target file is readable */ if (permissions & 0400) dir_permissions |= 0100; if (permissions & 0040) dir_permissions |= 0010; if (permissions & 0004) dir_permissions |= 0001; g_mkdir_with_parents (target_dir, dir_permissions); } args_len = 0; for (i = 0; args && args[i]; i++) args_len++; if (edit_mode) { if (args_len == 0) { g_printerr (_("Must specify a desktop file to process.\n")); return 1; } if (args_len > 1) { g_printerr (_("Only one desktop file can be processed at once.\n")); return 1; } } else { if (args_len == 0) { g_printerr (_("Must specify one or more desktop files to process.\n")); return 1; } } for (i = 0; args && args[i]; i++) { err = NULL; process_one_file (args[i], &err); if (err != NULL) { g_printerr (_("Error on file \"%s\": %s\n"), args[i], err->message); g_error_free (err); return 1; } } #if GLIB_CHECK_VERSION(2,28,0) g_slist_free_full (edit_actions, (GDestroyNotify) dfu_edit_action_free); #else g_slist_foreach (edit_actions, (GFunc) dfu_edit_action_free, NULL); g_slist_free (edit_actions); #endif g_option_context_free (context); return 0; }