unsigned long string_to_ulong(const std::string& source, bool* ok) { try { std::size_t pos = 0; const long long value = std::stoll(source, &pos); unsigned long result = 0; if (pos == source.length() && convert_to(value, result)) { if (ok) *ok = true; return result; } } catch (...) { if (ok) *ok = false; return 0; } if (ok) *ok = false; return 0; }
systemtime::systemtime( const codex::timestamp& ts ) { struct tm tm_date; convert_to( ts , tm_date ); wHour = tm_date.tm_hour; wMinute = tm_date.tm_min ; wDay = tm_date.tm_mday; wMonth = tm_date.tm_mon + 1; wSecond = tm_date.tm_sec ; wYear = tm_date.tm_year + 1900; wMilliseconds = static_cast<uint16_t>(( ts.tick() % (1000 * 1000)) / 1000) ; }
void do_convert(const char *n, const char *base) { char *s = convert_from(n, base), *tmp; printf("from: %s -> %s\n", n, s); tmp = s; s = convert_to(tmp, base); printf("to: %s -> %s\n", tmp, s); free(tmp); free(s); }
static int search_argument_smb_conf(char *buffer, size_t size, char *share, char *option, char **value) { char *argument=NULL; int nreturn=0; logoutput("search_argument_smb_conf: look for %s", share); if (buffer) { char *pos=NULL, *end; int len0=strlen(share); char section[len0+3]; /* construct the section for share [share] */ section[0]='['; memcpy(§ion[1], share, len0); section[len0+1]=']'; section[len0+2]='\0'; pos=strstr(buffer, section); if (pos) { while(pos<buffer+size) { end=strchr(pos, '\n'); if (! end || end==buffer+size) { break; } else { int len=end-pos; char line[len+1], *sep; memcpy(line, pos, len); *(line+len)='\0'; convert_to(line, UTILS_CONVERT_SKIPSPACE); sep=strchr(line, '='); if (sep) { *sep='\0'; if (strcmp(line, option)==0) { *value=strdup(sep+1); if (! *value) { nreturn=-ENOMEM; } else { nreturn=strlen(sep+1)+1; } break; } } else { if (*line=='[') { if (strcmp(line, section)!=0) break; } } } pos=end+1; } } else { nreturn=-ENOENT; } } return nreturn; }
filetime::filetime( const codex::timestamp& ts ) { convert_to( ts , *this ); }