Translated %ll print editing formats to %I64 on Windows
Older msvcrt.dll (on XP and earlier) did not support "%ll" print editing formats frequently used by ntfsclone. So translate them to "%I64" when running on Windows. This format appears to be supported by all Windows versions. Error messages from libntfs-3g are still not translated.edge.strict_endians
parent
e6eae9fa16
commit
c17512cde5
|
@ -1120,4 +1120,65 @@ int mft_next_record(struct mft_search_ctx *ctx)
|
|||
return (ctx->inode == NULL);
|
||||
}
|
||||
|
||||
#ifdef HAVE_WINDOWS_H
|
||||
|
||||
/*
|
||||
* Translate formats for older Windows
|
||||
*
|
||||
* Up to Windows XP, msvcrt.dll does not support long long format
|
||||
* specifications (%lld, %llx, etc). We have to translate them
|
||||
* to %I64.
|
||||
*/
|
||||
|
||||
char *ntfs_utils_reformat(char *out, int sz, const char *fmt)
|
||||
{
|
||||
const char *f;
|
||||
char *p;
|
||||
int i;
|
||||
enum { F_INIT, F_PERCENT, F_FIRST } state;
|
||||
|
||||
i = 0;
|
||||
f = fmt;
|
||||
p = out;
|
||||
state = F_INIT;
|
||||
while (*f && ((i + 3) < sz)) {
|
||||
switch (state) {
|
||||
case F_INIT :
|
||||
if (*f == '%')
|
||||
state = F_PERCENT;
|
||||
*p++ = *f++;
|
||||
i++;
|
||||
break;
|
||||
case F_PERCENT :
|
||||
if (*f == 'l') {
|
||||
state = F_FIRST;
|
||||
f++;
|
||||
} else {
|
||||
if (((*f < '0') || (*f > '9'))
|
||||
&& (*f != '*') && (*f != '-'))
|
||||
state = F_INIT;
|
||||
*p++ = *f++;
|
||||
i++;
|
||||
}
|
||||
break;
|
||||
case F_FIRST :
|
||||
if (*f == 'l') {
|
||||
*p++ = 'I';
|
||||
*p++ = '6';
|
||||
*p++ = '4';
|
||||
f++;
|
||||
i += 3;
|
||||
} else {
|
||||
*p++ = 'l';
|
||||
*p++ = *f++;
|
||||
i += 2;
|
||||
state = F_INIT;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
*p++ = 0;
|
||||
return (out);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -101,6 +101,26 @@ int mft_next_record(struct mft_search_ctx *ctx);
|
|||
#define MAX_PATH 1024
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_WINDOWS_H
|
||||
/*
|
||||
* Macroes to hide the needs to translate formats on older Windows
|
||||
*/
|
||||
#define MAX_FMT 256
|
||||
char *ntfs_utils_reformat(char *out, int sz, const char *fmt);
|
||||
#define ntfs_log_redirect(fn,fi,li,le,d,fmt, args...) \
|
||||
do { char buf[MAX_FMT]; ntfs_log_redirect(fn,fi,li,le,d, \
|
||||
ntfs_utils_reformat(buf,MAX_FMT,fmt), args); } while (0)
|
||||
#define printf(fmt, args...) \
|
||||
do { char buf[MAX_FMT]; \
|
||||
printf(ntfs_utils_reformat(buf,MAX_FMT,fmt), args); } while (0)
|
||||
#define fprintf(str, fmt, args...) \
|
||||
do { char buf[MAX_FMT]; \
|
||||
fprintf(str, ntfs_utils_reformat(buf,MAX_FMT,fmt), args); } while (0)
|
||||
#define vfprintf(file, fmt, args) \
|
||||
do { char buf[MAX_FMT]; vfprintf(file, \
|
||||
ntfs_utils_reformat(buf,MAX_FMT,fmt), args); } while (0)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* linux-ntfs's ntfs_mbstoucs has different semantics, so we emulate it with
|
||||
* ntfs-3g's.
|
||||
|
|
Loading…
Reference in New Issue