From c17512cde5c76c4cdc96aa5283807ff3bcfc7828 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Pierre=20Andr=C3=A9?= Date: Sat, 9 Feb 2013 12:57:22 +0100 Subject: [PATCH] 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. --- ntfsprogs/utils.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++ ntfsprogs/utils.h | 20 ++++++++++++++++ 2 files changed, 81 insertions(+) diff --git a/ntfsprogs/utils.c b/ntfsprogs/utils.c index 971e7fd8..781a2d6f 100644 --- a/ntfsprogs/utils.c +++ b/ntfsprogs/utils.c @@ -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 diff --git a/ntfsprogs/utils.h b/ntfsprogs/utils.h index 3974da00..839ce205 100644 --- a/ntfsprogs/utils.h +++ b/ntfsprogs/utils.h @@ -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.