static Errcode create_file(Pdr *pd, char *path, Image_file **pif, Anim_info *ainfo) /***************************************************************************** * create an output file (alloc, open, and write file header). ****************************************************************************/ { Errcode err; Targa_file *tf; (void)pd; tf = NULL; *pif = NULL; /* * allocate main data structures, open file. */ if (Success != (err = alloc_and_open(&tf, path, XWRITEONLY))) goto ERROR_EXIT; tf->width = ainfo->width; tf->height = ainfo->height; if (NULL == (tf->hsegbuf = pj_malloc(tf->width))) { err = Err_no_memory; goto ERROR_EXIT; } *pif = (Image_file *)tf; return Success; ERROR_EXIT: close_file((Image_file **)&tf); return err; }
static Errcode open_file(Pdr *pd, char *path, Image_file **pif, Anim_info *ainfo ) /***************************************************************************** * PDR file open function for Targa files. ****************************************************************************/ { Errcode err; Targa_file *tf; (void)pd; *pif = NULL; /* in case of error */ /* * allocate main data structures, open file. */ if (Success != (err = alloc_and_open(&tf, path, XREADONLY))) goto ERROR_EXIT; if (Success != (err = read_targa_header(tf))) goto ERROR_EXIT; if (ainfo != NULL) { ainfo->width = tf->width; ainfo->height = tf->height; ainfo->depth = tf->pdepth; ainfo->num_frames = 1; ainfo->millisec_per_frame = DEFAULT_AINFO_SPEED; } *pif = (Image_file *)tf; return Success; ERROR_EXIT: close_file((Image_file **)&tf); *pif = NULL; return(err); }
/* lnstat_scan_dir - find and parse all available statistics files/fields */ struct lnstat_file *lnstat_scan_dir(const char *path, const int num_req_files, const char **req_files) { DIR *dir; struct lnstat_file *lnstat_files = NULL; struct dirent *de; if (!path) path = PROC_NET_STAT; dir = opendir(path); if (!dir) { struct lnstat_file *lf; /* Old kernel, before /proc/net/stat was introduced */ fprintf(stderr, "Your kernel doesn't have lnstat support. "); /* we only support rtstat, not multiple files */ if (num_req_files >= 2) { fputc('\n', stderr); return NULL; } /* we really only accept rt_cache */ if (num_req_files && !name_in_array(num_req_files, req_files, "rt_cache")) { fputc('\n', stderr); return NULL; } fprintf(stderr, "Fallback to old rtstat-only operation\n"); lf = alloc_and_open("/proc/net", "rt_cache_stat"); if (!lf) return NULL; lf->compat = 1; strncpy(lf->basename, "rt_cache", sizeof(lf->basename)); /* FIXME: support for old files */ if (lnstat_scan_compat_rtstat_fields(lf) < 0) return NULL; lf->next = lnstat_files; lnstat_files = lf; return lnstat_files; } while ((de = readdir(dir))) { struct lnstat_file *lf; if (de->d_type != DT_REG) continue; if (num_req_files && !name_in_array(num_req_files, req_files, de->d_name)) continue; lf = alloc_and_open(path, de->d_name); if (!lf) return NULL; /* fill in field structure */ if (lnstat_scan_fields(lf) < 0) return NULL; /* prepend to global list */ lf->next = lnstat_files; lnstat_files = lf; } closedir(dir); return lnstat_files; }
struct lnstat_file *lnstat_scan_dir(const char *path, const int num_req_files, const char **req_files) { DIR *dir; struct lnstat_file *lnstat_files = NULL; struct dirent *de; if (!path) path = PROC_NET_STAT; dir = opendir(path); if (!dir) { struct lnstat_file *lf; fprintf(stderr, "Your kernel doesn't have lnstat support. "); if (num_req_files >= 2) { fputc('\n', stderr); return NULL; } if (num_req_files && !name_in_array(num_req_files, req_files, "rt_cache")) { fputc('\n', stderr); return NULL; } fprintf(stderr, "Fallback to old rtstat-only operation\n"); lf = alloc_and_open("/proc/net", "rt_cache_stat"); if (!lf) return NULL; lf->compat = 1; strncpy(lf->basename, "rt_cache", sizeof(lf->basename)); if (lnstat_scan_compat_rtstat_fields(lf) < 0) return NULL; lf->next = lnstat_files; lnstat_files = lf; return lnstat_files; } while ((de = readdir(dir))) { struct lnstat_file *lf; if (de->d_type != DT_REG) continue; if (num_req_files && !name_in_array(num_req_files, req_files, de->d_name)) continue; lf = alloc_and_open(path, de->d_name); if (!lf) return NULL; if (lnstat_scan_fields(lf) < 0) return NULL; lf->next = lnstat_files; lnstat_files = lf; } closedir(dir); return lnstat_files; }