/* helper for num_gen_parse() */ static rc_t num_gen_convert_and_add_ctx( num_gen* self, p_num_gen_parse_ctx ctx ) { char *endp; if ( self == NULL ) return RC( rcVDB, rcNoTarg, rcInserting, rcSelf, rcNull ); if ( ctx == NULL ) return RC( rcVDB, rcNoTarg, rcInserting, rcParam, rcNull ); if ( ctx->num_str_idx == 0 ) return RC( rcVDB, rcNoTarg, rcInserting, rcParam, rcEmpty ); /* terminate the source-string */ ctx->num_str[ ctx->num_str_idx ] = 0; /* convert the string into a uint64_t */ if ( ctx->this_is_the_first_number ) { ctx->num1 = strtou64( ctx->num_str, &endp, 10 ); ctx->num2 = ctx->num1; } else ctx->num2 = strtou64( ctx->num_str, &endp, 10 ); /* empty the source-string to be reused */ ctx->num_str_idx = 0; ctx->this_is_the_first_number = true; return num_gen_add_node( self, ctx->num1, ctx->num2 ); }
static uint64_t ArgsGetOptU64 ( Args *self, const ctx_t *ctx, const char *optname, uint32_t *count ) { rc_t rc; uint64_t val = 0; uint32_t dummy; if ( count == NULL ) count = & dummy; rc = ArgsOptionCount ( self, optname, count ); if ( rc == 0 && * count != 0 ) { const char *str; rc = ArgsOptionValue ( self, optname, 0, & str ); if ( rc != 0 ) INTERNAL_ERROR ( rc, "failed to retrieve '%s' parameter", optname ); else { char *end; val = strtou64 ( str, & end, 0 ); if ( end [ 0 ] != 0 ) { rc = RC ( rcExe, rcArgv, rcParsing, rcParam, rcIncorrect ); ERROR ( rc, "bad '%s' parameter: '%s'", optname, str ); } } } return val; }
static rc_t get_max_remove( const Args * args, uint64_t * max_rem ) { uint32_t count; rc_t rc = ArgsOptionCount( args, OPTION_MAXREM, &count ); if ( rc != 0 ) { PLOGERR( klogErr, ( klogErr, rc, "ArgsOptionCount( $(option) ) failed in $(func)", "option=%s,func=%s", OPTION_MAXREM, __func__ ) ); } else if ( count > 0 ) { const char * s = NULL; rc = ArgsOptionValue( args, OPTION_MAXREM, 0, &s ); if ( rc != 0 ) { PLOGERR( klogErr, ( klogErr, rc, "ArgsOptionValue( $(option), 0 ) failed in $(func)", "option=%s,func=%s", OPTION_MAXREM, __func__ ) ); } else if ( s != NULL ) { char *endp; *max_rem = strtou64( s, &endp, 10 ); } } return rc; }
static rc_t cg_dump_get_uint64t_option( Args * args, const char * name, uint64_t * value, bool * found ) { uint32_t count; rc_t rc = ArgsOptionCount( args, name, &count ); if ( rc != 0 ) { (void)PLOGERR( klogErr, ( klogErr, rc, "cannot detect count of $(name) option", "name=%s", name ) ); } else { *found = ( count > 0 ); } if ( rc == 0 && ( *found ) ) { const char * s; rc = ArgsOptionValue( args, name, 0, &s ); if ( rc != 0 ) { (void)PLOGERR( klogErr, ( klogErr, rc, "cannot detect value of $(name) option", "name=%s", name ) ); } else { char * endp; *value = strtou64( s, &endp, 10 ); } } return rc; }
static uint64_t NGS_StringToU64( const NGS_String * str, ctx_t ctx ) { /* have to guarantee NUL-termination for strtou64/strtod */ char buf[4096]; if ( sizeof(buf) > NGS_StringSize ( str, ctx ) ) { char* end; uint64_t value; string_copy ( buf, sizeof(buf), NGS_StringData ( str, ctx ), NGS_StringSize ( str, ctx ) ); errno = 0; value = strtou64 ( buf, &end, 10 ); if ( *end == 0 ) { if ( errno == 0 ) { return value; } } else { /* attempt to parse as a double */ double dbl; errno = 0; dbl = strtod ( buf, &end ); if ( *end == 0 && errno == 0 && dbl >= 0 && dbl <= ULLONG_MAX ) { return ( uint64_t ) xtrunc ( dbl ); } } } INTERNAL_ERROR ( xcUnexpected, "cannot convert dictionary value '%.*s' from string to uint64", NGS_StringSize ( str, ctx ), NGS_StringData ( str, ctx ) ); return 0; }
static uint64_t finish_num( char *s, size_t size, size_t *dst ) { uint64_t res = 0; char *endp; finish_txt( s, size, dst ); res = strtou64( s, &endp, 10 ); return res; }
/* helper for ng_parse() */ static void ng_convert_ctx( p_ng_parse_ctx ctx ) { char *endp; ctx->num_str[ ctx->num_str_idx ] = 0; ctx->num[ 0 ] = strtou64( ctx->num_str, &endp, 10 ); ctx->num_count = 1; ctx->num_str_idx = 0; }
/* helper for num_gen_parse() */ static void num_gen_convert_ctx( p_num_gen_parse_ctx ctx ) { char *endp; ctx->num_str[ ctx->num_str_idx ] = 0; ctx->num1 = strtou64( ctx->num_str, &endp, 10 ); ctx->this_is_the_first_number = false; ctx->num_str_idx = 0; }
static uint64_t KConfigGetNodeU64 ( const ctx_t *ctx, const char *path, bool *found ) { rc_t rc; uint64_t val = 0; const KConfigNode *n; bool dummy; if ( found == NULL ) found = & dummy; rc = KConfigOpenNodeRead ( ctx -> caps -> cfg, & n, "sra-sort/map_file_bsize" ); if ( rc == 0 ) { char buff [ 256 ]; size_t num_read, remaining; rc = KConfigNodeRead ( n, 0, buff, sizeof buff - 1, & num_read, & remaining ); if ( rc != 0 ) ERROR ( rc, "failed to read KConfig node '%s'", path ); else if ( remaining != 0 ) { rc = RC ( rcExe, rcNode, rcReading, rcBuffer, rcInsufficient ); ERROR ( rc, "failed to read KConfig node '%s'", path ); } else { char *end; buff [ num_read ] = 0; val = strtou64 ( buff, & end, 0 ); if ( end [ 0 ] != 0 ) { rc = RC ( rcExe, rcNode, rcReading, rcNumeral, rcIncorrect ); ERROR ( rc, "bad '%s' config value: '%s'", path, buff ); } } KConfigNodeRelease ( n ); } return val; }
/* helper for ng_parse() */ static uint32_t ng_convert_and_add_ctx( p_ng generator, p_ng_parse_ctx ctx ) { uint32_t res = 0; char *endp; if ( ctx->num_str_idx > 0 ) { ctx->num_str[ ctx->num_str_idx ] = 0; ctx->num[ ctx->num_count ] = strtou64( ctx->num_str, &endp, 10 ); ctx->num_str_idx = 0; if ( ctx->num_count == 0 ) { ctx->num[1] = ctx->num[0]; } if ( ng_add_node( generator, ctx->num[0], ctx->num[1] ) ) { res++; } ctx->num_count = 0; } return res; }
/* allocate a redact-value */ static p_redact_val redact_val_init( const char* name, const uint32_t len, const char* value ) { p_redact_val res = NULL; if ( name == NULL ) return res; if ( name[0] == 0 ) return res; res = calloc( 1, sizeof( redact_val ) ); if ( res == NULL ) return res; res->name = string_dup_measure ( name, NULL ); res->len = len; res->value = NULL; if ( value != NULL ) { if ( value[0] == '\'' && value[2] == '\'' ) { res->value = malloc( sizeof value[0] ); if ( res->value ) { res->len = 1; *( ( char * )res->value ) = value[1]; } } else { char *endptr; uint64_t x = strtou64( value, &endptr, 0 ); if ( res->len > sizeof x ) res->len = sizeof x; res->value = malloc( len ); if ( res->value ) memcpy( res->value, &x, res->len ); } } return res; }
static rc_t KWGAEncFileHeaderRead (KWGAEncFile * self) { KWGAEncFileHeader header; uint8_t * pb; size_t num_read; size_t tot_read; rc_t rc; assert (self); assert (sizeof (KWGAEncFileHeader) == 128); DEBUG_STS (("s: Enter '%p'\n", __func__, self)); pb = (void*)&header; for (num_read = tot_read = 0; tot_read < sizeof header; ) { rc = KFileRead (self->encrypted, (uint64_t)tot_read, pb, sizeof (header) - tot_read, &num_read); if (rc) { LOGERR (klogErr, rc, "Error reading the header for an encrypted file"); return rc; } if (num_read == 0) { rc = RC (rcFS, rcFile, rcReading, rcFile, rcInsufficient); LOGERR (klogErr, rc, "Header incomplete for an encrypted file"); return rc; } tot_read += num_read; pb += num_read; } KWGAEncFileHeaderDecrypt (&header); if (memcmp (header.magic, ncbi_crypt_magic, sizeof ncbi_crypt_magic) != 0) { rc = RC (rcFS, rcFile, rcReading, rcHeader, rcCorrupt); LOGERR (klogErr, rc, "Header's magic bad for encrypted file"); return rc; } /* so far unknown legal range */ self->block_size = strtou32 (header.block_sz, NULL, KWGA_ENC_FILE_HEADER_RADIX); self->file_size = strtou64 (header.file_sz, NULL, KWGA_ENC_FILE_HEADER_RADIX); /* file format has limiting feature of a 32 bit timestamp */ self->mtime = (KTime_t)strtol (header.mtime, NULL, KWGA_ENC_FILE_HEADER_RADIX); switch ((FER_ENCODING)header.fer_enc) { default: rc = RC (rcFS, rcFile, rcReading, rcHeader, rcOutofrange); LOGERR (klogErr, rc, "Enryption type code out of range"); return rc; case fer_encDES: case fer_encBLF: rc = RC (rcFS, rcFile, rcReading, rcHeader, rcIncorrect); LOGERR (klogErr, rc, "Enryption type code not supported"); return rc; case fer_encAES: break; } self->md5_here = (header.md5_here != 0); if (self->md5_here) memmove (self->md5, header.md5, sizeof (self->md5)); memmove (self->md51, header.md51, sizeof (self->md51)); return 0; /* yeah not really checking later errors am i? */ }