/* * Canonize file and paths names. E.g. convert this: * g:\mingw32\bin\../lib/gcc/x86_64-w64-mingw32/4.8.1/include * into something more readable: * g:\mingw32\lib\gcc\x86_64-w64-mingw32\4.8.1\include * * I.e. turns 'path' into a fully-qualified path. * * Note: the 'path' doesn't have to exist. * assumes 'result' is at least '_MAX_PATH' characters long (if non-NULL). */ char *_fixpath (const char *path, char *result) { if (!path || !*path) { DEBUGF (1, "given a bogus 'path'\n"); errno = EINVAL; return (NULL); } if (!result) result = CALLOC (_MAX_PATH, 1); /* GetFullPathName() doesn't seems to handle * '/' in 'path'. Convert to '\\'. * Note: the 'result' file or path may not exists. * Use 'FILE_EXISTS()' to test. * * to-do: maybe use GetLongPathName()? */ path = slashify (path, '\\'); if (!GetFullPathName(path, _MAX_PATH, result, NULL)) { DEBUGF (2, "GetFullPathName(\"%s\") failed: %s\n", path, win_strerror(GetLastError())); _strlcpy (result, path, _MAX_PATH); } return (result); }
static void add_to_mem_list (struct mem_head *m, const char *file, unsigned line) { m->next = mem_list; m->line = line; _strlcpy (m->file,file, sizeof(m->file)); mem_list = m; }
void SetupSequenceDebugFile() { char s[120]; if (Debug == dg_RandsUsed) _strlcpy(s, RandsDebugFn, sizeof(s)); else _strlcpy(s, SequenceDebugFn, sizeof(s)); if (operation == op_encrypt) strcat(s, ".enc"); else if (operation == op_decrypt) strcat(s, ".dec"); SeqDebugF = fopen(s, "w"); if (SeqDebugF == NULL) { Debug = 0; puts("Unable to create debug file"); } else { fprintf(SeqDebugF, "This file created using Debug Level %d by %s.\n", Debug, ProgramName); fprintf(SeqDebugF, "From file: %s\n", SrcFn); if(Debug == dg_Sequ4) { printf("Debugging Output mixer: File '%s' will contain sequence used, %u to a line.\n", s, bufsize); fprintf(SeqDebugF, "1st 2 entries on line are: number of sequences and num of mixes.\n"); fprintf(SeqDebugF, "Then the sequence of chars output follows. Numbers are decimal.\n"); } if (Debug == dg_RandsUsed) { printf("Debugging Randoms: File '%s' will contain randoms used, 1 line each.\n", s); fprintf(SeqDebugF, "The randoms used for the char follow. One character per line.\n"); } if (Debug == dg_Sequ || Debug == dg_Sequ2 || Debug == dg_Sequ3) { printf("Debugging Sequencing: File '%s' will contain sequences used, 1 line each.\n", s); fprintf(SeqDebugF, "1st entries on line are the CypherMode, num of layers used and the final xor.\n"); } if (Debug == dg_Sequ) fprintf(SeqDebugF, "The layer sequence follows. One character per line. A line is ~777 chars long.\n"); if (Debug == dg_Sequ2 || Debug == dg_Sequ3) fprintf(SeqDebugF, "The layer sequence of only those used follows. One character per line.\n"); if (Debug != dg_Sequ4) fprintf(SeqDebugF, "Password cypher begins here. LayersHighest = %u\n", PasswrdLayersHighest); } //else }
int DebugWriteRands(char *label) { DebugRands_t *rec; int BytesWrit = 0; if (dbRandsF == NULL) { msg("Unable to write to rands-debug file", 0); return 0; } rec = calloc(1, sizeof(DebugRands_t)); recs++; _strlcpy(rec->label, label, sizeof(rec->label)); memcpy(rec->rands, Rands, RandBytesMax); memcpy(rec->DocSeeds, DocSeeds, SubKeySeedsMax); BytesWrit = fwrite(rec, sizeof(DebugRands_t), 1, dbRandsF); if (BytesWrit !=1) printf("DEBUG ERROR: WriteRands, incorrect size (%d)\n", BytesWrit); free(rec); return 1; }
/* follows strftime() where appropriate */ static char *_fmttc(char *p, const char *limit, const char *format, Timecode const * const tc) { for ( ; *format; ++format) { if (*format == '%') { switch (*++format) { /* misc */ case '\0': --format; break; case 't': p= _strlcpy(p, limit, "\t"); continue; /* date, timezone */ case 'm': _fmtval(p, limit, "%02d", tc->d.month); continue; case 'd': _fmtval(p, limit, "%02d", tc->d.day); continue; case 'y': _fmtval(p, limit, "%02d", tc->d.year%100); continue; case 'Y': _fmtval(p, limit, "%04d", tc->d.year); continue; case 'z': _fmtval(p, limit, "%+03d%02d", tc->d.timezone/60, abs(tc->d.timezone)%60); continue; /* frame rate */ case ':': if (tc->r.drop) { p= _strlcpy(p, limit, ";"); } else { p= _strlcpy(p, limit, ":"); } continue; case 'f': if (tc->r.den == 1) { _fmtval(p, limit, "%d", tc->r.num); } else { _fmtval(p, limit, "%.2f", TCtoDbl(&tc->r)); } if (tc->r.drop) { p= _strlcpy(p, limit, "df"); } continue; /* time, frames */ case 'H': _fmtval(p, limit, "%02d", tc->t.hour); continue; case 'M': _fmtval(p, limit, "%02d", tc->t.minute); continue; case 'S': _fmtval(p, limit, "%02d", tc->t.second); continue; case 'F': { int lz = (tc->r.den < 1 || TCtoDbl(&tc->r) <= 1) ? 1 : ceil(log10(TCtoDbl(&tc->r))); char fmt[8]; snprintf(fmt, 8, "%%0%dd", lz%10); _fmtval(p, limit, fmt, tc->t.frame); } continue; case 's': { int lz = tc->r.subframes < 1 ? 1 : ceil(log10(tc->r.subframes)); char fmt[8]; snprintf(fmt, 8, "%%0%dd", lz%10); _fmtval(p, limit, fmt, tc->t.subframe); } continue; /* presets */ case 'T': p = _fmttc(p, limit, "%H:%M:%S%:%F", tc); continue; case 'Z': p = _fmttc(p, limit, "%Y-%m-%d %H:%M:%S%:%F.%s %z @%f fps", tc); continue; default: break; // out of select - ignore the '%' } } if (p == limit) break; // out of for-loop *p++ = *format; } return p; }