/** * @brief f_open - open the file * * @param f_name file name * * @return success/fail */ signed char f_open(const char *f_name) { if (file != NULL) { F_ERROR("file %s already open\n", f_name); return FILE_ERROR; } file = fopen(f_name, "r"); if (file == NULL) { F_ERROR("could not open file %s\n", f_name); return FILE_ERROR; } F_INFO("file %s opened\n", (char *)f_name); return FILE_OK; }
/** * @brief f_close - close the file * * @return pass/fail */ signed char f_close(void) { if (file == NULL) { F_ERROR("file is not open\n"); return FILE_ERROR; } if (fclose(file)) { F_ERROR("could not close file!\n"); file = NULL; return FILE_ERROR; } file = NULL; F_INFO("file closed\n"); return FILE_OK; }
/** * @brief f_size - returns the size of the file * * @param f_name - name of the file including path * * @return success/fail */ signed long f_size(const char *f_name) { struct stat f_stat; if (stat(f_name, &f_stat)) { F_ERROR("Could not stat %s\n", f_name); return FILE_ERROR; } F_INFO("File size is %d\n", (unsigned int)f_stat.st_size); return f_stat.st_size; }
/** * @brief f_seek - seek to location in file * * @param offset in file * * @return status */ int f_seek(long offset) { int ret; if (file == NULL) { F_ERROR("file is not open\n"); return FILE_ERROR; } ret = fseek(file, offset, SEEK_SET); F_INFO("seek operation returned %d\n", ret); return ret; }
/** * @brief f_read - read from file * * @param buffer buffer * @param read_size size to read * * @return num bytes read */ signed int f_read(unsigned char *buffer, unsigned int read_size) { int ret; if (file == NULL) { F_ERROR("file is not open\n"); return FILE_ERROR; } ret = fread(buffer, 1, read_size, file); F_INFO("read operation returned %d\n", ret); return ret; }
/* =========================================================================== Read a byte from a gz_stream; update next_in and avail_in. Return EOF for end of file. IN assertion: the stream s has been sucessfully opened for reading. */ static int get_byte( gz_stream *s) { if (s->z_eof) return EOF; if (s->stream.avail_in == 0) { s->stream.avail_in = F_READ(s->inbuf, 1, Z_BUFSIZE, s->file); if (s->stream.avail_in == 0) { s->z_eof = 1; if (F_ERROR(s->file)) s->z_err = Z_ERRNO; return EOF; } s->stream.next_in = s->inbuf; } s->stream.avail_in--; return *(s->stream.next_in)++; }
void yyinit( void ) { char *name, *value, *map_path; /* zero the line counter */ yylineno = 0; if( rulemap_path == NULL ) { NMloc( FILES, FILENAME, ERx( "default.rfm" ), &loc ); LOcopy( &loc, file_name, &loc ); LOtos( &loc, &map_path ); } else { STcopy( rulemap_path, file_name ); LOfroms( FILENAME, file_name, &loc ); map_path = rulemap_path; } (void) PMmInit( &rulemap ); if( PMmLoad( rulemap, &loc, PMerror ) != OK ) PCexit( FAIL ); /* initiate scan of rule map */ if( PMmScan( rulemap, ERx( ".*" ), &rfm_scan, NULL, &name, &value ) != OK ) { F_ERROR( "Rule file map %s is empty.", map_path ); } /* set up LOCATION of first rule file */ STcopy( value, file_name ); NMloc( FILES, FILENAME, file_name, &loc ); LOcopy( &loc, file_name, &loc ); /* initialize input pointer */ yyp = &dummy; /* open rule file */ if( SIfopen( &loc, ERx( "r" ), SI_TXT, SI_MAX_TXT_REC, &yyin ) != OK && yywrap() ) { ERROR( "No configuration rule files were found." ); } }
/* =========================================================================== Reads the given number of uncompressed bytes from the compressed file. lib_gzread returns the number of bytes actually read (0 for end of file). */ int lib_gzread (gzFile file, voidp buf, size_t len) { gz_stream *s = (gz_stream*)file; Bytef *start = (Bytef*)buf; /* starting point for crc computation */ Byte *next_out; /* == stream.next_out but not forced far (for MSDOS) */ if (s == NULL || s->mode != 'r') return Z_STREAM_ERROR; if (s->z_err == Z_DATA_ERROR || s->z_err == Z_ERRNO) return -1; if (s->z_err == Z_STREAM_END) return 0; /* EOF */ next_out = (Byte*)buf; s->stream.next_out = (Bytef*)buf; s->stream.avail_out = (uInt)len; while (s->stream.avail_out != 0) { if (s->transparent) { /* Copy first the lookahead bytes: */ uInt n = s->stream.avail_in; if (n > s->stream.avail_out) n = s->stream.avail_out; if (n > 0) { sysMemCpy(s->stream.next_out, s->stream.next_in, n); next_out += n; s->stream.next_out = next_out; s->stream.next_in += n; s->stream.avail_out -= n; s->stream.avail_in -= n; } if (s->stream.avail_out > 0) { s->stream.avail_out -= F_READ(next_out, 1, s->stream.avail_out, s->file); } len -= s->stream.avail_out; s->stream.total_in += (uLong)len; s->stream.total_out += (uLong)len; if (len == 0) s->z_eof = 1; return (int)len; } if (s->stream.avail_in == 0 && !s->z_eof) { s->stream.avail_in = F_READ(s->inbuf, 1, Z_BUFSIZE, s->file); if (s->stream.avail_in == 0) { s->z_eof = 1; if (F_ERROR(s->file)) { s->z_err = Z_ERRNO; break; } } s->stream.next_in = s->inbuf; } s->z_err = inflate(&(s->stream), Z_NO_FLUSH); if (s->z_err == Z_STREAM_END) { /* Check CRC and original size */ s->crc = crc32(s->crc, start, (uInt)(s->stream.next_out - start)); start = s->stream.next_out; if (getLong(s) != s->crc) { s->z_err = Z_DATA_ERROR; } else { (void)getLong(s); /* The uncompressed length returned by above getlong() may * be different from s->stream.total_out) in case of * concatenated .gz files. Check for such files: */ check_header(s); if (s->z_err == Z_OK) { uLong total_in = s->stream.total_in; uLong total_out = s->stream.total_out; inflateReset(&(s->stream)); s->stream.total_in = total_in; s->stream.total_out = total_out; s->crc = crc32(0L, Z_NULL, 0); } } } if (s->z_err != Z_OK || s->z_eof) break; } s->crc = crc32(s->crc, start, (uInt)(s->stream.next_out - start)); return (int)(len - s->stream.avail_out); }
/* PROGRAM = iijobdef ** NEEDLIBS = UTILLIB MALLOCLIB COMPATLIB GLLIB ** UNDEFS = II_copyright ** DEST = utility */ # endif /* VMS */ main( i4 argc, char **argv) { # ifdef VMS char *host; i4 i; PM_SCAN_REC state; STATUS status; char *lnm_table_name; struct dsc$descriptor lnm_table; char *regexp; char *name, *value; PM_CONTEXT *config; struct dsc$descriptor lnm_name; ILE3 item_list[ 2 ]; long access_mode = PSL$C_SUPER; bool failed_once = FALSE; /* lib$set_logical works? */ const match_1 = LIB$_NOCLI; /* Process has no CLI. */ const match_2 = LIB$_UNECLIERR; /* Unexpected CLI error * (non-standard CLI?). */ const match_3 = SS$_NORMAL; /* Normal return. */ const match_4 = SS$_SUPERSEDE; /* Replaced old value. */ const match_5 = SS$_NOLOGNAM; /* Not currently defined. */ bool delete_logs = FALSE; /* What are we doing? */ char *act_str; /* String for action. */ char *err_str; /* String for error exit. */ char *log_str; /* String to log action. */ char tmp_buf[BIG_ENOUGH]; MEadvise( ME_INGRES_ALLOC ); if( argc != 1 ) delete_logs = TRUE; (void) PMmInit( &config ); if( PMmLoad( config, NULL, PMerror ) != OK ) PCexit( FAIL ); host = PMmHost( config ); PMmSetDefault( config, HOST_PM_IDX, host ); /* get logical table name */ STprintf (tmp_buf , ERx( "%s.$.lnm.table.id" ), SystemCfgPrefix); if( PMmGet( config, tmp_buf , &lnm_table_name ) != OK ) { F_ERROR( "%s not found.", PMmExpandRequest( config, tmp_buf ) ); } /* set logical name table */ lnm_table_name = ERx( "LNM$JOB" ); /* compose string descriptor for logical table name */ lnm_table.dsc$w_length = STlength( lnm_table_name ); lnm_table.dsc$a_pointer = lnm_table_name; lnm_table.dsc$b_class = DSC$K_CLASS_S; lnm_table.dsc$b_dtype = DSC$K_DTYPE_T; if ( delete_logs ) { act_str = ERx( "\nDeleting %s logicals...\n\n(%s)\n\n" ); err_str = ERx( "Unable to deassign %s.\n\n" ); log_str = ERx( "" ); } else { act_str = ERx( "\nDeleting %s logicals...\n\n(%s)\n\n" ); err_str = ERx( "Unable to set %s to \"%s\".\n\n" ); log_str = ERx( "\"%s\" = \"%s\"\n" ); } F_PRINT2( act_str, SystemDBMSName, lnm_table_name ); /* scan and set node-specific logicals */ regexp = PMmExpToRegExp( config, ERx( "ii.$.lnm.%") ); for( status = PMmScan( config, regexp, &state, NULL, &name, &value ); status == OK; status = PMmScan( config, NULL, &state, NULL, &name, &value ) ) { name = PMmGetElem( config, 3, name ); lnm_name.dsc$w_length = STlength( name ); lnm_name.dsc$a_pointer = name; lnm_name.dsc$b_class = DSC$K_CLASS_S; lnm_name.dsc$b_dtype = DSC$K_DTYPE_T; item_list[ 0 ].ile3$w_length = STlength( value ); item_list[ 0 ].ile3$w_code = LNM$_STRING; item_list[ 0 ].ile3$ps_bufaddr = value; item_list[ 0 ].ile3$ps_retlen_addr = NULL; item_list[ 1 ].ile3$w_length = 0; item_list[ 1 ].ile3$w_code = 0; if ( !failed_once ) { if ( delete_logs ) status = lib$delete_logical( &lnm_name, &lnm_table ); else status = lib$set_logical( &lnm_name, NULL, &lnm_table, NULL, item_list ); if ( lib$match_cond( &status, &match_1, &match_2 )) failed_once = TRUE; } if ( failed_once ) { if ( delete_logs ) status = sys$dellnm( &lnm_table, &lnm_name, &access_mode ); else status = sys$crelnm( NULL, &lnm_table, &lnm_name, &access_mode, item_list ); } if ( !lib$match_cond( &status, &match_3, &match_4, &match_5 )) { SIfprintf( stderr, err_str, name, value ); PCexit( FAIL ); } SIprintf( log_str, name, value ); } PCexit( OK ); # else /* VMS */ SIprintf( "\nThis doesn't do much.\n\n" ); # endif /* VMS */ }