// Main program body. int main (int argc, char *argv[]) { char *inFile, *maskFile, *outFile; int currArg = 1; int NUM_ARGS = 3; handle_license_and_version_args(argc, argv, ASF_NAME_STRING); asfSplashScreen(argc, argv); if (argc<=1) usage(ASF_NAME_STRING); else if (strmatches(argv[1],"-help","--help",NULL)) print_help(); while (currArg < (argc-NUM_ARGS)) { char *key = argv[currArg++]; if (strmatches(key,"-help","--help",NULL)) { print_help(); // doesn't return } else if (strmatches(key,"-log","--log",NULL)) { CHECK_ARG(1); strcpy(logFile,GET_ARG(1)); fLog = FOPEN(logFile, "a"); logflag = TRUE; } else if (strmatches(key,"-quiet","--quiet","-q",NULL)) { quietflag = TRUE; } else { --currArg; break; } } if ((argc-currArg) < NUM_ARGS) { printf("Insufficient arguments.\n"); usage(argv[0]); } else if ((argc-currArg) > NUM_ARGS) { printf("Unknown argument: %s\n", argv[currArg]); usage(argv[0]); } inFile = argv[currArg]; maskFile = argv[currArg+1]; outFile = argv[currArg+2]; char *in_base = get_basename(inFile); char *out_base = get_basename(outFile); asfPrintStatus("Clipping image: %s -> %s\n", in_base, out_base); clip(inFile, maskFile, outFile); asfPrintStatus("Done.\n"); free(in_base); free(out_base); return EXIT_SUCCESS; }
void *sm_realloc(const char *fname, int lineno, void *ptr, unsigned int size) { unsigned osize; void *buf; char *cp = (char *) ptr; Dmsg4(DT_MEMORY|50, "sm_realloc %s:%d %p %d\n", get_basename(fname), (uint32_t)lineno, ptr, size); if (size <= 0) { e_msg(fname, lineno, M_ABORT, 0, _("sm_realloc size: %d\n"), size); } /* If the old block pointer is NULL, treat realloc() as a malloc(). SVID is silent on this, but many C libraries permit this. */ if (ptr == NULL) { return sm_malloc(fname, lineno, size); } /* If the old and new sizes are the same, be a nice guy and just return the buffer passed in. */ cp -= HEAD_SIZE; struct abufhead *head = (struct abufhead *)cp; osize = head->ablen - (HEAD_SIZE + 1); if (size == osize) { return ptr; } /* Sizes differ. Allocate a new buffer of the requested size. If we can't obtain such a buffer, act as defined in SVID: return NULL from realloc() and leave the buffer in PTR intact. */ // sm_buffers--; // sm_bytes -= head->ablen; if ((buf = smalloc(fname, lineno, size)) != NULL) { memcpy(buf, ptr, (int)sm_min(size, osize)); /* If the new buffer is larger than the old, fill the balance of it with "designer garbage". */ if (size > osize) { memset(((char *) buf) + osize, 0x55, (int) (size - osize)); } /* All done. Free and dechain the original buffer. */ sm_free(fname, lineno, ptr); } Dmsg4(DT_MEMORY|60, _("sm_realloc %d at %p from %s:%d\n"), size, buf, get_basename(fname), (uint32_t)lineno); return buf; }
/* SM_CHECK -- Check the buffers and dump if any damage exists. */ void sm_check(const char *fname, int lineno, bool bufdump) { if (!sm_check_rtn(fname, lineno, bufdump)) { Emsg2(M_ABORT, 0, _("Damaged buffer found. Called from %s:%d\n"), get_basename(fname), (uint32_t)lineno); } }
/** * Print EDonkey 2000 url for given file to a stream. * * @param out the stream where to print url to * @param filename the file name * @param filesize the file size * @param sums the file hash sums */ static void fprint_ed2k_url(FILE* out, struct file_info *info, int print_type) { const char *filename = get_basename(file_info_get_utf8_print_path(info)); int upper_case = (print_type & PRINT_FLAG_UPPERCASE ? RHPR_UPPERCASE : 0); int len = urlencode(NULL, filename) + int_len(info->size) + (info->sums_flags & RHASH_AICH ? 84 : 49); char* buf = (char*)rsh_malloc( len + 1 ); char* dst = buf; assert(info->sums_flags & (RHASH_ED2K|RHASH_AICH)); assert(info->rctx); strcpy(dst, "ed2k://|file|"); dst += 13; dst += urlencode(dst, filename); *dst++ = '|'; sprintI64(dst, info->size, 0); dst += strlen(dst); *dst++ = '|'; rhash_print(dst, info->rctx, RHASH_ED2K, upper_case); dst += 32; if((info->sums_flags & RHASH_AICH) != 0) { strcpy(dst, "|h="); rhash_print(dst += 3, info->rctx, RHASH_AICH, RHPR_BASE32 | upper_case); dst += 32; } strcpy(dst, "|/"); fprintf(out, "%s", buf); free(buf); }
static int archive_buffer_load(EditBuffer *b, FILE *f) { /* Launch subprocess to list archive contents */ char cmd[1024]; ArchiveType *atp; atp = find_archive_type(b->filename); if (atp) { eb_clear(b); eb_printf(b, " Directory of %s archive %s\n", atp->name, b->filename); snprintf(cmd, sizeof(cmd), atp->list_cmd, b->filename); new_shell_buffer(b, get_basename(b->filename), NULL, cmd, SF_INFINITE | SF_BUFED_MODE); /* XXX: should check for archiver error */ /* XXX: should delay BF_SAVELOG until buffer is fully loaded */ b->flags |= BF_READONLY; return 0; } else { eb_printf(b, "Cannot find archiver\n"); return -1; } }
/* SM_CHECK -- Check the buffers and dump if any damage exists. */ void sm_check(const char *fname, int lineno, bool bufdump) { if (!sm_check_rtn(fname, lineno, bufdump)) { smart_alloc_msg(__FILE__, __LINE__, _("Damaged buffer found. Called from %s:%d\n"), get_basename(fname), (uint32_t)lineno); } }
/*************************************************************************** * get_load_order (internal) * * Return the loadorder of a module. * The system directory and '.dll' extension is stripped from the path. */ enum loadorder get_load_order( const WCHAR *app_name, const WCHAR *path ) { enum loadorder ret = LO_INVALID; HANDLE std_key, app_key = 0; WCHAR *module, *basename; UNICODE_STRING path_str; int len; if (!init_done) init_load_order(); std_key = get_standard_key(); if (app_name) app_key = get_app_key( app_name ); TRACE("looking for %s\n", debugstr_w(path)); /* Strip path information if the module resides in the system directory */ RtlInitUnicodeString( &path_str, path ); if (RtlPrefixUnicodeString( &system_dir, &path_str, TRUE )) { const WCHAR *p = path + system_dir.Length / sizeof(WCHAR); while (*p == '\\' || *p == '/') p++; if (!strchrW( p, '\\' ) && !strchrW( p, '/' )) path = p; } if (!(len = strlenW(path))) return ret; if (!(module = RtlAllocateHeap( GetProcessHeap(), 0, (len + 2) * sizeof(WCHAR) ))) return ret; strcpyW( module+1, path ); /* reserve module[0] for the wildcard char */ basename = (WCHAR *)get_basename( module+1 ); if (len >= 4) remove_dll_ext( module + 1 + len - 4 ); /* first explicit module name */ if ((ret = get_load_order_value( std_key, app_key, module+1 )) != LO_INVALID) goto done; /* then module basename preceded by '*' */ basename[-1] = '*'; if ((ret = get_load_order_value( std_key, app_key, basename-1 )) != LO_INVALID) goto done; /* then module basename without '*' (only if explicit path) */ if (basename != module+1 && ((ret = get_load_order_value( std_key, app_key, basename )) != LO_INVALID)) goto done; /* if loading the main exe with an explicit path, try native first */ if (!app_name && basename != module+1) { ret = LO_NATIVE_BUILTIN; TRACE( "got main exe default %s for %s\n", debugstr_loadorder(ret), debugstr_w(path) ); goto done; } /* and last the hard-coded default */ ret = LO_DEFAULT; TRACE( "got hardcoded %s for %s\n", debugstr_loadorder(ret), debugstr_w(path) ); done: RtlFreeHeap( GetProcessHeap(), 0, module ); return ret; }
int build_filelist(char *input, char *output, filelist_t *filelist, int file_type) { struct dirent **files; int x = 0; struct stat st_in; if (stat(input, &st_in) != 0 ) { dcp_log(LOG_ERROR,"Could not open input file %s",input); return DCP_FATAL; } filelist->file_count = scandir(input,&files,(void *)file_filter,alphasort); if (filelist->file_count) { for (x=0;x<filelist->file_count;x++) { sprintf(filelist->in[x],"%s/%s",input,files[x]->d_name); if (file_type == J2K_INPUT) { sprintf(filelist->out[x],"%s/%s.j2c",output,get_basename(files[x]->d_name)); } } } for (x=0;x<filelist->file_count;x++) { free(files[x]); } free(files); return DCP_SUCCESS; }
int main (int argc, char *argv[]) { char inDataName[255], inMetaName[255], *baseName; /* cla parsing */ handle_common_asf_args(&argc, &argv, "c2p"); /* After extracting the optional flags, should have 2 args left */ if (argc != 3) usage(argv[0]); /* Make sure input and output names are different */ if (strcmp(argv[1],argv[2])==SAME) { printf("c2p: Input and output names cannot be the same. Exiting.\n"); exit(EXIT_FAILURE); } // Assign filenames and check their existence baseName = (char *) MALLOC(sizeof(char)*255); baseName = get_basename(argv[1]); sprintf(inDataName, "%s.img", baseName); if (!fileExists(inDataName)) asfPrintError("Data file (%s) does not exist.\n", inDataName); sprintf(inMetaName, "%s.meta", baseName); if (!fileExists(inMetaName)) asfPrintError("Metadata file (%s) does not exist.\n", inMetaName); /* Do it! */ c2p_ext(inDataName, inMetaName, argv[2], FALSE, FALSE); if (logflag) FCLOSE(fLog); return 0; }
static void set_defaults(ImageInfo *ii) { // default filename char *basename = get_basename(ii->filename); char *def = appendStr(basename, "_aoi"); if (strncmp_case(def, "LED-", 4) == 0 || strncmp_case(def, "IMG-", 4) == 0 || strncmp_case(def, "TRL-", 4) == 0 || strncmp_case(def, "VOL-", 4) == 0) { char *tmp = STRDUP(def+4); free(def); def = tmp; } free(basename); put_string_to_entry("filename_entry", def); free(def); // default directory char *dir = get_dirname(ii->filename); if (dir && strlen(dir) > 0) put_string_to_entry("dir_entry", dir); else put_string_to_entry("dir_entry", ""); FREE(dir); // default data to save (Pixel Values) set_combo_box_item("data_combobox", 0); }
int xmp_load_module(xmp_context opaque, char *path) { struct context_data *ctx = (struct context_data *)opaque; struct module_data *m = &ctx->m; HIO_HANDLE *h; struct stat st; struct list_head tmpfiles_list; D_(D_WARN "path = %s", path); if (stat(path, &st) < 0) return -XMP_ERROR_SYSTEM; #ifndef _MSC_VER if (S_ISDIR(st.st_mode)) { errno = EISDIR; return -XMP_ERROR_SYSTEM; } #endif if ((h = hio_open_file(path, "rb")) == NULL) return -XMP_ERROR_SYSTEM; INIT_LIST_HEAD(&tmpfiles_list); D_(D_INFO "decrunch"); if (decrunch(&tmpfiles_list, &h->f, &path, DECRUNCH_MAX) < 0) goto err_depack; if (hio_stat(h, &st) < 0) goto err_depack; if (st.st_size < 256) { /* get size after decrunch */ hio_close(h); unlink_tempfiles(&tmpfiles_list); return -XMP_ERROR_FORMAT; } if (ctx->state > XMP_STATE_UNLOADED) xmp_release_module(opaque); m->dirname = get_dirname(path); if (m->dirname == NULL) return -XMP_ERROR_SYSTEM; m->basename = get_basename(path); if (m->basename == NULL) return -XMP_ERROR_SYSTEM; m->filename = path; /* For ALM, SSMT, etc */ m->size = st.st_size; return load_module(opaque, h, &tmpfiles_list); err_depack: hio_close(h); unlink_tempfiles(&tmpfiles_list); return -XMP_ERROR_DEPACK; }
int main(int argc, char **argv) { char name[40]; get_basename(name, 40, argv[0]); testcreatepidfile(name); printf("This is test program for luoyun cloud program!\n"); return (0); }
/* walk through the directory of the loaded file and add every file matching the current file */ void fileset_add_dir(const char *fname) { WS_DIR *dir; /* scanned directory */ WS_DIRENT *file; /* current file */ const char *name; fileset_entry *entry; GString *dirname; gchar *fname_dup; /* get (convert) directory name, but don't touch the given string */ fname_dup = get_dirname(g_strdup(fname)); dirname = g_string_new(fname_dup); g_free(fname_dup); set.dirname = g_strdup(dirname->str); dirname = g_string_append_c(dirname, G_DIR_SEPARATOR); /* is the current file probably a part of any fileset? */ if(fileset_filename_match_pattern(fname)) { /* yes, go through the files in the directory and check if the file in question is part of the current file set */ if ((dir = ws_dir_open(dirname->str, 0, NULL)) != NULL) { while ((file = ws_dir_read_name(dir)) != NULL) { name = ws_dir_get_name(file); if(fileset_filename_match_pattern(name) && fileset_is_file_in_set(name, get_basename(fname))) { fileset_add_file(dirname->str, name, strcmp(name, get_basename(fname))== 0 /* current */); } } /* while */ ws_dir_close(dir); } /* if */ } else { /* no, this is a "standalone file", just add this one */ entry = fileset_add_file(dirname->str, get_basename(fname), TRUE /* current */); /* don't add the file to the dialog here, this will be done in fileset_update_dlg() below */ } g_string_free(dirname, TRUE /* free_segment */); /* sort entries by creation time */ set.entries = g_list_sort(set.entries, fileset_sort_compare); fileset_update_dlg(); }
int test_get_basename() { static const size_t sz = SCRATCH_SZ; static const size_t small_sz = SMALL_SCRATCH_SZ; int errors = 0; char scratch[SCRATCH_SZ]; char small_scratch[SMALL_SCRATCH_SZ]; #ifdef _UNIX_ scratch[0] = '\0'; if ( get_basename( "/hi/there", scratch, sz ) || strcmp("there", scratch) ) { ++errors; LOG("get_basename fail with absolute path '/hi/there' ['%s']\n", scratch); } #else //windows scratch[0] = '\0'; if ( get_basename( "c:/hi/there", scratch, sz ) || strcmp("there", scratch) ) { ++errors; LOG("get_basename fail with absolute path 'c:/hi/there ['%s']'\n", scratch); } scratch[0] = '\0'; if ( get_basename( "c:\\hi\\there", scratch, sz ) || strcmp("there", scratch) ) { ++errors; LOG("get_basename fail with absolute path 'c:\\hi\\there ['%s']'\n", scratch); } #endif scratch[0] = '\0'; if ( get_basename( "./hi/there", scratch, sz ) || strcmp("there", scratch) ) { ++errors; LOG("get_basename fail with explicit relative path './hi/there' ['%s']\n", scratch); } scratch[0] = '\0'; if ( get_basename( "../hi/there", scratch, sz ) || strcmp("there", scratch) ) { ++errors; LOG("get_basename fail with explicit relative path '../hi/there' ['%s']\n", scratch); } scratch[0] = '\0'; if ( get_basename( "hi/there", scratch, sz ) || strcmp("there", scratch) ) { ++errors; LOG("get_basename fail with relative path 'hi/there ['%s']'\n", scratch); } small_scratch[0] = '\0'; if ( get_basename( "/hi/there", small_scratch, small_sz ) || strcmp("there", small_scratch) ) { ++errors; LOG("get_basename fail with long absolute path '/hi/there' ['%s']\n", small_scratch); } return errors; }
static int dm_test_device(struct lib_context *lc, char *path) { struct stat s; return !lstat(path, &s) && /* S_ISLNK(s.st_mode) && */ /* No symlinks any more. */ !strncmp(get_basename(lc, path), "dm-", 3); }
/** * fit_write_images() - Write out a list of images to the FIT * * We always include the main image (params->datafile). If there are device * tree files, we include an fdt@ node for each of those too. */ static int fit_write_images(struct image_tool_params *params, char *fdt) { struct content_info *cont; const char *typename; char str[100]; int upto; int ret; fdt_begin_node(fdt, "images"); /* First the main image */ typename = genimg_get_type_short_name(params->fit_image_type); snprintf(str, sizeof(str), "%s@1", typename); fdt_begin_node(fdt, str); fdt_property_string(fdt, "description", params->imagename); fdt_property_string(fdt, "type", typename); fdt_property_string(fdt, "arch", genimg_get_arch_name(params->arch)); fdt_property_string(fdt, "os", genimg_get_os_short_name(params->os)); fdt_property_string(fdt, "compression", genimg_get_comp_short_name(params->comp)); fdt_property_u32(fdt, "load", params->addr); fdt_property_u32(fdt, "entry", params->ep); /* * Put data last since it is large. SPL may only load the first part * of the DT, so this way it can access all the above fields. */ ret = fdt_property_file(params, fdt, "data", params->datafile); if (ret) return ret; fdt_end_node(fdt); /* Now the device tree files if available */ upto = 0; for (cont = params->content_head; cont; cont = cont->next) { if (cont->type != IH_TYPE_FLATDT) continue; snprintf(str, sizeof(str), "%s@%d", FIT_FDT_PROP, ++upto); fdt_begin_node(fdt, str); get_basename(str, sizeof(str), cont->fname); fdt_property_string(fdt, "description", str); ret = fdt_property_file(params, fdt, "data", cont->fname); if (ret) return ret; fdt_property_string(fdt, "type", typename); fdt_property_string(fdt, "arch", genimg_get_arch_short_name(params->arch)); fdt_property_string(fdt, "compression", genimg_get_comp_short_name(IH_COMP_NONE)); fdt_end_node(fdt); } fdt_end_node(fdt); return 0; }
void add_file(const char *data_file) { char *base = get_basename(data_file); put_cached_image(base, "loc1", "image_loc1"); put_cached_image(base, "loc2", "image_loc2"); put_cached_image(base, "loc3", "image_loc3"); put_cached_image(base, "thumb_sml", "image_radar"); }
/* ==================================================================== Return the domain out of the given parse-tree. If not contained, construct the domain from the file name. Will be allocated on the heap. ==================================================================== */ char *determine_domain(struct PData *tree, const char *filename) { char *domain; char *pos; if ( parser_get_string(tree, "domain", &domain) ) return domain; domain = strdup(get_basename(filename)); pos = strchr(domain, '.'); if (pos) *pos = 0; return domain; }
static int _install_app(transport_type transport, char* serial, int argc, char** argv) { static const char *const DATA_DEST = "/data/local/tmp/%s"; static const char *const SD_DEST = "/sdcard/tmp/%s"; const char* where = DATA_DEST; int i; struct stat sb; for (i = 1; i < argc; i++) { if (!strcmp(argv[i], "-s")) { where = SD_DEST; } } // Find last APK argument. // All other arguments passed through verbatim. int last_apk = -1; for (i = argc - 1; i >= 0; i--) { char* file = argv[i]; char* dot = strrchr(file, '.'); if (dot && !strcasecmp(dot, ".apk")) { if (stat(file, &sb) == -1 || !S_ISREG(sb.st_mode)) { return -1; } last_apk = i; break; } } if (last_apk == -1) { return -1; } char* apk_file = argv[last_apk]; char apk_dest[PATH_MAX]; snprintf(apk_dest, sizeof apk_dest, where, get_basename(apk_file)); int err = _do_sync_push(apk_file, apk_dest, 0 /* no show progress */); if (err) { goto cleanup_apk; } else { argv[last_apk] = apk_dest; /* destination name, not source location */ } char *result=_pm_command(transport, serial, argc, argv); if(result==NULL||strstr(result, "Success")==NULL) { err=5; } free(result); cleanup_apk: _delete_file(transport, serial, apk_dest); return err; }
const char *get_extension(const char *filename) { filename = get_basename(filename); const char *extension = strrchr(filename, '.'); if (!extension) { /* no extension? bummer. point to the \0 at the end of the string. */ extension = strchr(filename, '\0'); } return extension; }
/* SM_DUMP -- Print orphaned buffers (and dump them if BUFDUMP is * True). */ void sm_dump(bool bufdump, bool in_use) { struct abufhead *ap; P(mutex); ap = (struct abufhead *)abqueue.qnext; while (ap != (struct abufhead *) &abqueue) { if ((ap == NULL) || (ap->abq.qnext->qprev != (struct b_queue *) ap) || (ap->abq.qprev->qnext != (struct b_queue *) ap)) { Pmsg1(0, _( "\nOrphaned buffers exist. Dump terminated following\n" " discovery of bad links in chain of orphaned buffers.\n" " Buffer address with bad links: %p\n"), ap); break; } if (ap->abfname != NULL) { char errmsg[500]; uint32_t memsize = ap->ablen - (HEAD_SIZE + 1); char *cp = ((char *)ap) + HEAD_SIZE; Pmsg6(0, "%s buffer: %s %d bytes at %p from %s:%d\n", in_use?"In use":"Orphaned", my_name, memsize, cp, get_basename(ap->abfname), ap->ablineno); if (bufdump) { char buf[20]; unsigned llen = 0; errmsg[0] = EOS; while (memsize) { if (llen >= 16) { bstrncat(errmsg, "\n", sizeof(errmsg)); llen = 0; Pmsg1(0, "%s", errmsg); errmsg[0] = EOS; } bsnprintf(buf, sizeof(buf), " %02X", (*cp++) & 0xFF); bstrncat(errmsg, buf, sizeof(errmsg)); llen++; memsize--; } Pmsg1(0, "%s\n", errmsg); } } ap = (struct abufhead *) ap->abq.qnext; } V(mutex); }
int ispolygon(char *inFile) { int isPolygon=0; char *line=NULL, *s; FILE *fp; fp = fopen(inFile, "r"); if (!fp) { char n[1024]; sprintf(n, "%s.csv", inFile); fp = fopen(n, "r"); } if (!fp) { char *basename = get_basename(inFile); char n[1024]; sprintf(n, "%s.csv", basename); fp = fopen(n, "r"); FREE(basename); } if (fp) { line = (char*)MALLOC(sizeof(char)*LINE_MAX); int line_count=0; while (fgets(line, LINE_MAX, fp)) { line[strlen(line)-1] = '\0'; s=line; while(isspace((int)(*s))) ++s; if (*s == '#') { char *tok = strtok(s,","); if (tok) { s = strstr(uc(tok), "FILE"); if (s && strncmp(uc(s), "FILE", 4) == 0) { tok = strtok(NULL, ","); if (tok) { s = strstr(uc(tok), "POLYGON"); if (s && strncmp(uc(s), "POLYGON", 7) == 0) { isPolygon = 1; break; } } } } } // avoid scanning the entire contents of a huge file if (++line_count>100) break; } } FREE(line); FCLOSE(fp); return isPolygon; }
/* is this a probable file of a file set (does the naming pattern match)? */ gboolean fileset_filename_match_pattern(const char *fname) { char *pfx; size_t baselen; size_t minlen = strlen("_00001_20050418010750"); char *filename; /* d:\dir1\test_00001_20050418010750.cap */ filename = g_strdup(get_basename(fname)); /* test_00001_20050418010750.cap */ pfx = strrchr(filename, '.'); if(pfx == NULL) { /* suffix is optional */ pfx = filename + strlen(filename); } /* test_00001_20050418010750 */ *pfx = '\0'; /* filename long enough? */ baselen = strlen(filename); if(baselen < minlen) { g_free(filename); return FALSE; } /* there must be two underscores at special places */ if(filename[baselen-minlen] != '_' || filename[baselen-minlen+6] != '_') { g_free(filename); return FALSE; } /* replace the two underscores by digits */ filename[baselen-minlen] = '0'; filename[baselen-minlen+6] = '0'; /* we should have only digits now */ while(minlen--) { baselen--; if(!isdigit( (guchar) filename[baselen])) { g_free(filename); return FALSE; } } g_free(filename); /* ok, seems to be good */ return TRUE; }
static ArchiveType *find_archive_type(const char *filename) { char rname[MAX_FILENAME_SIZE]; ArchiveType *atp; /* File extension based test */ reduce_filename(rname, sizeof(rname), get_basename(filename)); for (atp = archive_types; atp; atp = atp->next) { if (match_extension(rname, atp->extensions)) return atp; } return NULL; }
static CompressType *find_compress_type(const char *filename) { char rname[MAX_FILENAME_SIZE]; CompressType *ctp; /* File extension based test */ reduce_filename(rname, sizeof(rname), get_basename(filename)); for (ctp = compress_types; ctp; ctp = ctp->next) { if (match_extension(rname, ctp->extensions)) return ctp; } return NULL; }
static void add_uploaded_file (RecvFSM *fsm) { fsm->uploaded_files = g_list_prepend (fsm->uploaded_files, get_basename(fsm->file_name)); fsm->tmp_files = g_list_prepend (fsm->tmp_files, g_strdup(fsm->tmp_file)); g_free (fsm->file_name); g_free (fsm->tmp_file); close (fsm->fd); fsm->file_name = NULL; fsm->tmp_file = NULL; }
static int init_ctx_outbase(struct ccx_s_options *opt, struct lib_ccx_ctx *ctx) { char *file; if (opt->output_filename) { ctx->basefilename = get_basename(opt->output_filename); } else { switch (opt->input_source) { case CCX_DS_FILE: if(!ctx->inputfile || !ctx->inputfile[0]) { errno = EINVAL; return -1; } file = ctx->inputfile[0]; break; case CCX_DS_STDIN: file = "stdin"; break; case CCX_DS_NETWORK: case CCX_DS_TCP: file = "network"; break; default: errno = EINVAL; return -1; } ctx->basefilename = get_basename(file); } return 0; }
void switch_output_file(struct lib_ccx_ctx *ctx, struct encoder_ctx *enc_ctx, int track_id) { if (enc_ctx->out->filename != NULL) { // Close and release the previous handle free(enc_ctx->out->filename); close(enc_ctx->out->fh); } char *ext = get_file_extension(ctx->write_format); char suffix[32]; sprintf(suffix, "_%d", track_id); enc_ctx->out->filename = create_outfilename(get_basename(enc_ctx->first_input_file), suffix, ext); enc_ctx->out->fh = open(enc_ctx->out->filename, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, S_IREAD | S_IWRITE); // Reset counters as we switch output file. enc_ctx->cea_708_counter = 0; enc_ctx->srt_counter = 0; }
static int wget_buffer_load(EditBuffer *b, FILE *f) { /* Launch wget subprocess to retrieve contents */ char cmd[1024]; eb_clear(b); snprintf(cmd, sizeof(cmd), "wget -q -O - %s", b->filename); new_shell_buffer(b, get_basename(b->filename), NULL, cmd, SF_INFINITE | SF_AUTO_CODING | SF_AUTO_MODE); /* XXX: should check for wget error */ /* XXX: should delay BF_SAVELOG until buffer is fully loaded */ b->flags |= BF_READONLY; return 0; }
bool Desktop::save_icons_positions(void) { DesktopConfig pos; DesktopIcon *o; char *base; for(int i = 0; i < children(); i++) { if(NOT_SELECTABLE(child(i))) continue; o = (DesktopIcon*)child(i); base = get_basename(o->get_path()); pos.set(base, "X", o->x()); pos.set(base, "Y", o->y()); } return pos.save(ICONS_POS_FILE); }