From 1226d98038a81ac0a5f10cc160bcd1204b79480b Mon Sep 17 00:00:00 2001 From: "cantab.net!aia21" Date: Tue, 6 Jan 2004 11:04:29 +0000 Subject: [PATCH] Add compatibility for building with DJGPP under DOS. (Christophe Grenier, slightly modified by me) (Logical change 1.247) --- CREDITS | 1 + ChangeLog | 2 ++ config.h.in | 12 +++++++++--- configure | 8 +++++--- configure.ac | 6 +++--- include/endians.h | 8 ++++++-- include/volume.h | 8 +++++--- libntfs/unistr.c | 32 ++++++++++++++++++++++++++++++++ 8 files changed, 63 insertions(+), 14 deletions(-) diff --git a/CREDITS b/CREDITS index a10114d0..48c04864 100644 --- a/CREDITS +++ b/CREDITS @@ -11,6 +11,7 @@ Anton Altaparmakov Albert D. Cahalan Russ Christensen Matthew J. Fanto +Christophe Grenier Ian Jackson Jan Kratochvil Lode Leroy diff --git a/ChangeLog b/ChangeLog index d27fb331..4eca51f6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,8 @@ - Add new API function runlist.[hc]:ntfs_rl_pread(). - Fix bug in run list encoding functions that hit sparse and compressed files with holes. (Szabolcs Szakacsits) + - Add compatibility for building with DJGPP under DOS. (Christophe + Grenier, slightly modified by me) 19/11/2003 - 1.8.0 - Final fixes and tidy ups. - Cleanup build system wrt CFLAGS handling placing it all in one place diff --git a/config.h.in b/config.h.in index 2fae2ab4..9252b29b 100644 --- a/config.h.in +++ b/config.h.in @@ -1,17 +1,20 @@ /* config.h.in. Generated from configure.ac by autoheader. */ -/* Define to 1 if you have the header file. */ -#undef HAVE_ASM_BYTEORDER_H - /* Define to 1 if you have the `atexit' function. */ #undef HAVE_ATEXIT +/* Define to 1 if you have the header file. */ +#undef HAVE_BYTESWAP_H + /* Define to 1 if you have the header file. */ #undef HAVE_DLFCN_H /* Define to 1 if you don't have `vprintf' but do have `_doprnt.' */ #undef HAVE_DOPRNT +/* Define to 1 if you have the header file. */ +#undef HAVE_ENDIAN_H + /* Define to 1 if you have the header file. */ #undef HAVE_ERRNO_H @@ -59,6 +62,9 @@ /* Define to 1 if mbrtowc and mbstate_t are properly declared. */ #undef HAVE_MBRTOWC +/* Define to 1 if you have the `mbsinit' function. */ +#undef HAVE_MBSINIT + /* Define to 1 if you have the `memmove' function. */ #undef HAVE_MEMMOVE diff --git a/configure b/configure index 3c66b08b..f98bf20b 100755 --- a/configure +++ b/configure @@ -8460,12 +8460,13 @@ fi + for ac_header in fcntl.h libintl.h limits.h locale.h mntent.h stddef.h \ stdint.h stdlib.h stdio.h stdarg.h string.h strings.h errno.h time.h \ - sys/ioctl.h sys/mount.h unistd.h utime.h wchar.h getopt.h sys/stat.h \ - sys/types.h asm/byteorder.h linux/major.h linux/fd.h + endian.h byteswap.h sys/ioctl.h sys/mount.h unistd.h utime.h wchar.h \ + getopt.h sys/stat.h sys/types.h linux/major.h linux/fd.h do as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh` if eval "test \"\${$as_ac_Header+set}\" = set"; then @@ -10671,8 +10672,9 @@ done + for ac_func in atexit fdatasync hasmntopt memmove memset regcomp setlocale \ - strcasecmp strchr strdup strerror strtol strtoul utime + strcasecmp strchr strdup strerror strtol strtoul utime mbsinit do as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` echo "$as_me:$LINENO: checking for $ac_func" >&5 diff --git a/configure.ac b/configure.ac index 91dce96a..97846e5f 100644 --- a/configure.ac +++ b/configure.ac @@ -167,8 +167,8 @@ AC_SUBST(AUTODIRS) AC_HEADER_STDC AC_CHECK_HEADERS([fcntl.h libintl.h limits.h locale.h mntent.h stddef.h \ stdint.h stdlib.h stdio.h stdarg.h string.h strings.h errno.h time.h \ - sys/ioctl.h sys/mount.h unistd.h utime.h wchar.h getopt.h sys/stat.h \ - sys/types.h asm/byteorder.h linux/major.h linux/fd.h]) + endian.h byteswap.h sys/ioctl.h sys/mount.h unistd.h utime.h wchar.h \ + getopt.h sys/stat.h sys/types.h linux/major.h linux/fd.h]) # Checks for typedefs, structures, and compiler characteristics. AC_HEADER_STDBOOL @@ -192,7 +192,7 @@ AC_FUNC_STRFTIME AC_FUNC_UTIME_NULL AC_FUNC_VPRINTF AC_CHECK_FUNCS([atexit fdatasync hasmntopt memmove memset regcomp setlocale \ - strcasecmp strchr strdup strerror strtol strtoul utime]) + strcasecmp strchr strdup strerror strtol strtoul utime mbsinit]) # Makefiles to be created by configure. AC_CONFIG_FILES([ diff --git a/include/endians.h b/include/endians.h index 6f7f271f..d7d0133f 100644 --- a/include/endians.h +++ b/include/endians.h @@ -33,8 +33,12 @@ * architectures requiring aligned memory accesses... */ -#include -#include +#ifdef HAVE_ENDIAN_H +# include +#endif +#ifdef HAVE_BYTESWAP_H +# include +#endif #if (__BYTE_ORDER == __LITTLE_ENDIAN) diff --git a/include/volume.h b/include/volume.h index 9e3b77a1..ee5e2d17 100644 --- a/include/volume.h +++ b/include/volume.h @@ -25,13 +25,15 @@ #include "config.h" #include -#include +#ifdef HAVE_SYS_MOUNT_H +# include +#endif #ifdef HAVE_MNTENT_H # include #endif -/* Cygwin doesn't seem to have MS_RDONLY, so we define it here. */ -#if defined(__CYGWIN32__) && !defined(MS_RDONLY) +/* Both under Cygwin and DJGPP we do not have MS_RDONLY, so we define it. */ +#if !defined(MS_RDONLY) typedef enum { MS_RDONLY = 1, } MS_MOUNT; diff --git a/libntfs/unistr.c b/libntfs/unistr.c index a8267af5..2fc0e0af 100644 --- a/libntfs/unistr.c +++ b/libntfs/unistr.c @@ -321,7 +321,9 @@ int ntfs_ucstombs(const uchar_t *ins, const int ins_len, char **outs, wchar_t wc; int i, o, mbs_len; int cnt = 0; +#ifdef HAVE_MBSINIT mbstate_t mbstate; +#endif if (!ins || !outs) { errno = EINVAL; @@ -339,7 +341,11 @@ int ntfs_ucstombs(const uchar_t *ins, const int ins_len, char **outs, if (!mbs) return -1; } +#ifdef HAVE_MBSINIT memset(&mbstate, 0, sizeof(mbstate)); +#else + wctomb(NULL, 0); +#endif for (i = o = 0; i < ins_len; i++) { /* Reallocate memory if necessary or abort. */ if ((int)(o + MB_CUR_MAX) > mbs_len) { @@ -361,7 +367,11 @@ int ntfs_ucstombs(const uchar_t *ins, const int ins_len, char **outs, if (!wc) break; /* Convert the CPU endian wide character to multibyte. */ +#ifdef HAVE_MBSINIT cnt = wcrtomb(mbs + o, wc, &mbstate); +#else + cnt = wctomb(mbs + o, wc); +#endif if (cnt == -1) goto err_out; if (cnt <= 0) { @@ -371,12 +381,14 @@ int ntfs_ucstombs(const uchar_t *ins, const int ins_len, char **outs, } o += cnt; } +#ifdef HAVE_MBSINIT /* Make sure we are back in the initial state. */ if (!mbsinit(&mbstate)) { Dputs("Eeek. mbstate not in initial state!"); errno = EILSEQ; goto err_out; } +#endif /* Now write the NULL character. */ mbs[o] = '\0'; if (*outs != mbs) @@ -421,7 +433,9 @@ int ntfs_mbstoucs(char *ins, uchar_t **outs, int outs_len) char *s; wchar_t wc; int i, o, cnt, ins_len, ucs_len; +#ifdef HAVE_MBSINIT mbstate_t mbstate; +#endif if (!ins || !outs) { errno = EINVAL; @@ -435,11 +449,19 @@ int ntfs_mbstoucs(char *ins, uchar_t **outs, int outs_len) } /* Determine the length of the multi-byte string. */ s = ins; +#ifdef HAVE_MBSINIT memset(&mbstate, 0, sizeof(mbstate)); ins_len = mbsrtowcs(NULL, (const char **)&s, 0, &mbstate); +#else + ins_len = mbstowcs(NULL, s, 0); +#endif if (ins_len == -1) return ins_len; +#ifdef HAVE_MBSINIT if ((s != ins) || !mbsinit(&mbstate)) { +#else + if (s != ins) { +#endif errno = EILSEQ; return -1; } @@ -451,7 +473,11 @@ int ntfs_mbstoucs(char *ins, uchar_t **outs, int outs_len) if (!ucs) return -1; } +#ifdef HAVE_MBSINIT memset(&mbstate, 0, sizeof(mbstate)); +#else + mbtowc(NULL, NULL, 0); +#endif for (i = o = cnt = 0; o < ins_len; i += cnt, o++) { /* Reallocate memory if necessary or abort. */ if (o >= ucs_len) { @@ -472,7 +498,11 @@ int ntfs_mbstoucs(char *ins, uchar_t **outs, int outs_len) ucs_len /= sizeof(uchar_t); } /* Convert the multibyte character to a wide character. */ +#ifdef HAVE_MBSINIT cnt = mbrtowc(&wc, ins + i, ins_len - i, &mbstate); +#else + cnt = mbtowc(&wc, ins + i, ins_len - i); +#endif if (!cnt) break; if (cnt == -1) @@ -491,6 +521,7 @@ int ntfs_mbstoucs(char *ins, uchar_t **outs, int outs_len) /* Convert the CPU wide character to a LE Unicode character. */ ucs[o] = cpu_to_le16(wc); } +#ifdef HAVE_MBSINIT /* Make sure we are back in the initial state. */ if (!mbsinit(&mbstate)) { Dprintf("%s(): Eeek. mbstate not in initial state!\n", @@ -498,6 +529,7 @@ int ntfs_mbstoucs(char *ins, uchar_t **outs, int outs_len) errno = EILSEQ; goto err_out; } +#endif /* Now write the NULL character. */ ucs[o] = cpu_to_le16(L'\0'); if (*outs != ucs)