/* * Copy 'how_much' bytes from the input file to the output file, * starting at byte 'where' in the input file. * * Returns 0 on success, -1 on failure. */ herr_t copy_to_file( FILE *infid, FILE *ofid, ssize_t _where, ssize_t how_much ) { static char buf[COPY_BUF_SIZE]; off_t where = (off_t)_where; off_t to; off_t from; herr_t ret_value = 0; /* nothing to copy */ if(how_much <= 0) goto done; /* rewind */ HDfseek(infid, 0L, 0); from = where; to = 0; while(how_much > 0) { size_t bytes_in = 0; /* # of bytes to read */ size_t bytes_read = 0; /* # of bytes actually read */ size_t bytes_wrote = 0; /* # of bytes written */ if (how_much > COPY_BUF_SIZE) bytes_in = COPY_BUF_SIZE; else bytes_in = how_much; /* Seek to correct position in input file */ HDfseek(infid, from, SEEK_SET); /* Read data to buffer */ bytes_read = HDfread(buf, (size_t)1, bytes_in, infid); if(0 == bytes_read && HDferror(infid)) { ret_value = -1; goto done; } /* end if */ if(0 == bytes_read && HDfeof(infid)) { goto done; } /* end if */ /* Seek to correct position in output file */ HDfseek(ofid, to, SEEK_SET); /* Update positions/size */ how_much -= bytes_read; from += bytes_read; to += bytes_read; /* Write nchars bytes to output file */ bytes_wrote = HDfwrite(buf, (size_t)1, bytes_read, ofid); if(bytes_wrote != bytes_read || (0 == bytes_wrote && HDferror(ofid))) { /* error */ ret_value = -1; goto done; } /* end if */ } /* end while */ done: return ret_value; } /* end copy_to_file */
/*------------------------------------------------------------------------- * Function: insert_libhdf5_settings * * Purpose: insert the contents of libhdf5.settings into a file * represented by flibinfo. * Make it an empty string if H5_HAVE_EMBEDDED_LIBINFO is not * defined, i.e., not enabled. * * Return: void *------------------------------------------------------------------------- */ static void insert_libhdf5_settings(FILE *flibinfo) { #ifdef H5_HAVE_EMBEDDED_LIBINFO FILE *fsettings; /* for files libhdf5.settings */ int inchar; int bol = 0; /* indicates the beginning of a new line */ if(NULL == (fsettings = HDfopen(LIBSETTINGSFNAME, "r"))) { HDperror(LIBSETTINGSFNAME); HDexit(EXIT_FAILURE); } /* end if */ /* print variable definition and the string */ /* Do not use const else AIX strings does not show it. */ fprintf(flibinfo, "char H5libhdf5_settings[]=\n"); bol++; while(EOF != (inchar = HDgetc(fsettings))) { if(bol) { /* Start a new line */ fprintf(flibinfo, "\t\""); bol = 0; } /* end if */ if(inchar == '\n') { /* end of a line */ fprintf(flibinfo, "\\n\"\n"); bol++; } /* end if */ else HDputc(inchar, flibinfo); } /* end while */ if(HDfeof(fsettings)) { /* wrap up */ if(!bol) /* EOF found without a new line */ fprintf(flibinfo, "\\n\"\n"); fprintf(flibinfo, ";\n\n"); } /* end if */ else { fprintf(stderr, "Read errors encountered with %s\n", LIBSETTINGSFNAME); HDexit(EXIT_FAILURE); } /* end else */ if(0 != HDfclose(fsettings)) { HDperror(LIBSETTINGSFNAME); HDexit(EXIT_FAILURE); } /* end if */ #else /* print variable definition and an empty string */ /* Do not use const else AIX strings does not show it. */ fprintf(flibinfo, "char H5libhdf5_settings[]=\"\";\n"); #endif } /* insert_libhdf5_settings() */
static int read_info(const char *filename, pack_opt_t *options) { char stype[10]; char comp_info[1024]; FILE *fp = NULL; char c; int i, rc = 1; int ret_value = EXIT_SUCCESS; if ((fp = HDfopen(filename, "r")) == (FILE *) NULL) { error_msg("cannot open options file %s\n", filename); h5tools_setstatus(EXIT_FAILURE); ret_value = EXIT_FAILURE; goto done; } /* cycle until end of file reached */ while (1) { rc = fscanf(fp, "%s", stype); if (rc == -1) break; /*------------------------------------------------------------------------- * filter *------------------------------------------------------------------------- */ if (HDstrcmp(stype,"-f") == 0) { /* find begining of info */ i = 0; c = '0'; while (c != ' ') { fscanf(fp, "%c", &c); if (HDfeof(fp)) break; } c = '0'; /* go until end */ while (c != ' ') { fscanf(fp, "%c", &c); comp_info[i] = c; i++; if (HDfeof(fp)) break; if (c == 10 /*eol*/) break; } comp_info[i - 1] = '\0'; /*cut the last " */ if (h5repack_addfilter(comp_info, options) == -1) { error_msg("could not add compression option\n"); h5tools_setstatus(EXIT_FAILURE); ret_value = EXIT_FAILURE; goto done; } } /*------------------------------------------------------------------------- * layout *------------------------------------------------------------------------- */ else if (HDstrcmp(stype,"-l") == 0) { /* find begining of info */ i = 0; c = '0'; while (c != ' ') { fscanf(fp, "%c", &c); if (HDfeof(fp)) break; } c = '0'; /* go until end */ while (c != ' ') { fscanf(fp, "%c", &c); comp_info[i] = c; i++; if (HDfeof(fp)) break; if (c == 10 /*eol*/) break; } comp_info[i - 1] = '\0'; /*cut the last " */ if (h5repack_addlayout(comp_info, options) == -1) { error_msg("could not add chunck option\n"); h5tools_setstatus(EXIT_FAILURE); ret_value = EXIT_FAILURE; goto done; } } /*------------------------------------------------------------------------- * not valid *------------------------------------------------------------------------- */ else { error_msg("bad file format for %s", filename); h5tools_setstatus(EXIT_FAILURE); ret_value = EXIT_FAILURE; goto done; } } done: if (fp) HDfclose(fp); return ret_value; }
static void read_info(const char *filename, pack_opt_t *options) { char stype[10]; char comp_info[1024]; FILE *fp; char c; int i, rc=1; char *srcdir = getenv("srcdir"); /* the source directory */ char data_file[512]=""; /* buffer to hold name of existing file */ /* compose the name of the file to open, using the srcdir, if appropriate */ if (srcdir){ HDstrcpy(data_file,srcdir); HDstrcat(data_file,"/"); } HDstrcat(data_file,filename); if ((fp = HDfopen(data_file, "r")) == (FILE *)NULL) { error_msg("cannot open options file %s\n", filename); HDexit(EXIT_FAILURE); } /* cycle until end of file reached */ while( 1 ) { rc=fscanf(fp, "%s", stype); if (rc==-1) break; /*------------------------------------------------------------------------- * filter *------------------------------------------------------------------------- */ if (HDstrcmp(stype,"-f") == 0) { /* find begining of info */ i=0; c='0'; while( c!=' ' ) { fscanf(fp, "%c", &c); if (HDfeof(fp)) break; } c='0'; /* go until end */ while( c!=' ' ) { fscanf(fp, "%c", &c); comp_info[i]=c; i++; if (HDfeof(fp)) break; if (c==10 /*eol*/) break; } comp_info[i-1]='\0'; /*cut the last " */ if (h5repack_addfilter(comp_info,options)==-1){ error_msg("could not add compression option\n"); HDexit(EXIT_FAILURE); } } /*------------------------------------------------------------------------- * layout *------------------------------------------------------------------------- */ else if (HDstrcmp(stype,"-l") == 0) { /* find begining of info */ i=0; c='0'; while( c!=' ' ) { fscanf(fp, "%c", &c); if (HDfeof(fp)) break; } c='0'; /* go until end */ while( c!=' ' ) { fscanf(fp, "%c", &c); comp_info[i]=c; i++; if (HDfeof(fp)) break; if (c==10 /*eol*/) break; } comp_info[i-1]='\0'; /*cut the last " */ if (h5repack_addlayout(comp_info,options)==-1){ error_msg("could not add chunck option\n"); HDexit(EXIT_FAILURE); } } /*------------------------------------------------------------------------- * not valid *------------------------------------------------------------------------- */ else { error_msg("bad file format for %s", filename); HDexit(EXIT_FAILURE); } } HDfclose(fp); return; }