Imported Upstream version 4.0.43
[platform/upstream/mtools.git] / sysincludes.h
index 958ac61..5436dcb 100644 (file)
@@ -1,4 +1,4 @@
-/*  Copyright 1996-1999,2001,2002,2007-2009 Alain Knaff.
+/*  Copyright 1996-1999,2001,2002,2007-2009,2022 Alain Knaff.
  *  This file is part of mtools.
  *
  *  Mtools is free software: you can redistribute it and/or modify
@@ -20,9 +20,6 @@
 #ifndef SYSINCLUDES_H
 #define SYSINCLUDES_H
 
-#define _LARGEFILE64_SOURCE
-#define _GNU_SOURCE
-
 #include "config.h"
 
 
@@ -54,9 +51,9 @@
 
 
 /* On AIX, we have to prefer strings.h, as string.h lacks a prototype
- * for strcasecmp. On most other architectures, it's string.h which seems
- * to be more complete */
-#if (defined OS_aix && defined HAVE_STRINGS_H)
+ * for strcasecmp. On Solaris, string.h lacks a prototype for strncasecmp_l.
+ * On most other architectures, it's string.h which seems to be more complete */
+#if ((defined OS_aix || defined OS_solaris) && defined HAVE_STRINGS_H)
 # undef HAVE_STRING_H
 #endif
 
@@ -135,9 +132,6 @@ typedef void *caddr_t;
 /*                                                                     */
 /***********************************************************************/
 
-#define _LARGEFILE64_SOURCE
-#define _GNU_SOURCE
-
 #ifdef HAVE_ASSERT_H
 # include <assert.h>
 #endif
@@ -146,13 +140,18 @@ typedef void *caddr_t;
 # include <features.h>
 #endif
 
-
-#include <sys/types.h>
+#ifdef HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
 
 #ifdef HAVE_STDINT_H
 # include <stdint.h>
 #endif
 
+#ifdef HAVE_STDARG_H
+# include <stdarg.h>
+#endif
+
 #if HAVE_STDBOOL_H
 # include <stdbool.h>
 #else
@@ -184,10 +183,6 @@ typedef unsigned char _Bool;
 # include <unistd.h>
 #endif
 
-#ifdef HAVE_LINUX_UNISTD_H
-# include <linux/unistd.h>
-#endif
-
 #ifdef HAVE_LIBC_H
 # include <libc.h>
 #endif
@@ -196,6 +191,11 @@ typedef unsigned char _Bool;
 # include <getopt.h>
 #endif
 
+#if !HAVE_DECL_OPTARG
+extern char *optarg;
+extern int optind;
+#endif
+
 #ifdef HAVE_FCNTL_H
 # include <fcntl.h>
 #endif
@@ -219,14 +219,11 @@ typedef unsigned char _Bool;
  * suppress warnings if the platform is broken, as long as these warnings do
  * not prevent compilation */
 
-#ifdef TIME_WITH_SYS_TIME
-# include <sys/time.h>
+#ifdef HAVE_TIME_H
 # include <time.h>
 #else
 # ifdef HAVE_SYS_TIME_H
 #  include <sys/time.h>
-# else
-#  include <time.h>
 # endif
 #endif
 
@@ -286,8 +283,9 @@ extern int ioctl(int fildes, int request, void *arg);
 # endif
 #endif
 
-
-#include <sys/stat.h>
+#ifdef HAVE_SYS_STAT_H
+# include <sys/stat.h>
+#endif
 
 #include <errno.h>
 #ifndef errno
@@ -339,9 +337,24 @@ extern int errno;
 
 #ifdef HAVE_WCHAR_H
 # include <wchar.h>
+# ifdef HAVE_WCTYPE_H
+#  include <wctype.h>
+# endif
 # ifndef HAVE_PUTWC
 #  define putwc(c,f) fprintf((f),"%lc",(c))
 # endif
+# ifndef HAVE_WCSDUP
+wchar_t *wcsdup(const wchar_t *wcs);
+# endif
+
+# ifndef HAVE_WCSCASECMP
+int wcscasecmp(const wchar_t *s1, const wchar_t *s2);
+# endif
+
+# ifndef HAVE_WCSNLEN
+size_t wcsnlen(const wchar_t *wcs, size_t l);
+# endif
+
 #else
 # define wcscmp strcmp
 # define wcscasecmp strcasecmp
@@ -349,13 +362,9 @@ extern int errno;
 # define wcslen strlen
 # define wcschr strchr
 # define wcspbrk strpbrk
-# define wchar_t char
+# define wchar_t unsigned char
+# define wint_t int
 # define putwc putc
-#endif
-
-#ifdef HAVE_WCTYPE_H
-# include <wctype.h>
-#else
 # define towupper(x) toupper(x)
 # define towlower(x) tolower(x)
 # define iswupper(x) isupper(x)
@@ -371,38 +380,6 @@ extern int errno;
 # include <xlocale.h>
 #endif
 
-#ifdef USE_FLOPPYD
-
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
-
-#ifdef HAVE_NETINET_IN_H
-#include <netinet/in.h>
-#endif
-
-#ifdef HAVE_NETINET_TCP_H
-#include <netinet/tcp.h>
-#endif
-
-#ifdef HAVE_ARPA_INET_H
-#include <arpa/inet.h>
-#endif
-
-#ifdef HAVE_NETDB_H
-#include <netdb.h>
-#endif
-
-#ifdef HAVE_X11_XAUTH_H
-#include <X11/Xauth.h>
-#endif
-
-#ifdef HAVE_X11_XLIB_H
-#include <X11/Xlib.h>
-#endif
-
-#endif
-
 #ifndef INADDR_NONE
 #define INADDR_NONE (-1)
 #endif
@@ -443,6 +420,9 @@ extern int errno;
 # define strrchr rindex
 #endif
 
+#ifndef HAVE_STRSTR
+extern char * strstr (const char* haystack, const char *needle);
+#endif
 
 #ifndef HAVE_STRDUP
 extern char *strdup(const char *str);
@@ -509,21 +489,6 @@ int strncasecmp(const char *s1, const char *s2, size_t n);
 char *getpass(const char *prompt);
 #endif
 
-#ifdef HAVE_WCHAR_H
-
-# ifndef HAVE_WCSDUP
-wchar_t *wcsdup(const wchar_t *wcs);
-# endif
-
-# ifndef HAVE_WCSCASECMP
-int wcscasecmp(const wchar_t *s1, const wchar_t *s2);
-# endif
-
-# ifndef HAVE_WCSNLEN
-size_t wcsnlen(const wchar_t *wcs, size_t l);
-# endif
-
-#endif
 
 #if 0
 #ifndef HAVE_BASENAME
@@ -541,6 +506,32 @@ void _stripexe(char *filename);
 # endif
 #endif /* !__STDC__ */
 
+#ifndef UINT8_MAX
+#define UINT8_MAX (0xff)
+#endif
+
+#ifndef UINT16_MAX
+#define UINT16_MAX (0xffff)
+#endif
+
+#ifndef UINT32_MAX
+#define UINT32_MAX (0xffffffffU)
+#endif
+
+#ifndef O_ACCMODE
+#define O_ACCMODE (O_RDONLY | O_RDWR | O_WRONLY)
+#endif
+
+
+#if defined OS_hpux || \
+    defined OS_sunos || defined OS_solaris || \
+    defined OS_linux || \
+    (defined _SCO_DS) && (defined SCSIUSERCMD) || \
+    defined sgi || \
+    (defined OS_freebsd) && (__FreeBSD__ >= 2) || \
+    defined(OS_netbsd) || defined(OS_netbsdelf)
+# define HAVE_SCSI
+#endif
 
 
 /***************************************************************************/
@@ -633,6 +624,75 @@ struct utimbuf
 # undef HAVE_OFFSET_T
 #endif
 
+#if (defined (CPU_m68000) && defined (OS_sysv))
+/* AT&T UnixPC lacks prototypes for some system functions */
+void *calloc(size_t nmemb, size_t size);
+ssize_t read(int fd, void *buf, size_t count);
+ssize_t write(int fd, const void *buf, size_t count);
+int access(const char *pathname, int mode);
+int open(const char *path, int oflag, ...);
+int close(int fildes);
+int lockf(int fd, int cmd, off_t len);
+off_t lseek(int fd, off_t offset, int whence);
+int ioctl(int fd, unsigned long request, ...);
+int fcntl(int fd, int cmd, ...);
+int pipe(int pipefd[2]);
+int dup(int oldfd);
+int stat(const char *path, struct stat *buf);
+int fstat(int fd, struct stat *statbuf);
+#define S_ISREG(x) ((x)&S_IFREG)
+#define S_ISDIR(x) ((x)&S_IFDIR)
+#define S_ISLNK(x) (0)
+int toupper(int c);
+int tolower(int c);
+void srand48(long seed);
+long lrand48(void);
+time_t time(time_t *);
+long strtol(const char *str, char **ptr, int base);
+int printf(const char *format, ...);
+int fprintf(FILE *stream, const char *format, ...);
+int sprintf(char *s, const char *format, ...);
+int vfprintf(FILE *stream, const char *format, ...);
+int sscanf(const char *str, const char *format, ...);
+int fclose(FILE *stream);
+void perror(const char *s);
+int fflush(FILE *stream);
+size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);
+size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
+void exit(int status);
+int fputs(char *, FILE *stream);
+int fputc(int c, FILE *stream);
+int fgetc(FILE *stream);
+int isatty(int fd);
+int atexit(void (*function)(void));
+int getuid(void);
+int geteuid(void);
+int getegid(void);
+int getgid(void);
+int setuid(uid_t uid);
+int setgid(gid_t gid);
+void bcopy(const void *src, void *dest, size_t n);
+int _flsbuf(unsigned char x, FILE *p);
+pid_t fork(void);
+int execl(const char *pathname, const char *arg, ...);
+int execvp(const char *file, char *const argv[]);
+pid_t wait(int *stat_loc);
+int kill(pid_t pid, int sig);
+char *getpass(const char *prompt);
+int getopt(int argc, char * const argv[], const char *optstring);
+char *getenv(const char *name);
+char *getlogin(void);
+struct passwd *getpwnam(const char *name);
+struct passwd *getpwuid(uid_t uid);
+int unlink(const char *pathname);
+int access(const char *pathname, int mode);
+int mkdir (const char* file, int mode);
+unsigned int sleep(unsigned int seconds);
+#endif
+
+#ifndef HAVE_LSTAT
+#define lstat stat
+#endif
 
 #ifdef HAVE_STAT64
 #define MT_STAT stat64
@@ -649,10 +709,22 @@ struct utimbuf
 #define O_LARGEFILE 0
 #endif
 
-#ifndef __GNUC__
-#ifndef __inline__
-#define __inline__ inline
+#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) || defined(__clang__)
+# define HAVE_PRAGMA_DIAGNOSTIC 1
 #endif
+
+
+#if SIZEOF_SIZE_T > SIZEOF_LONG
+# define SZF "%llu"
+# define SSZF "%lld"
+#else
+# if SIZEOF_SIZE_T > SIZEOF_INT
+#  define SZF "%lu"
+#  define SSZF "%ld"
+# else
+#  define SZF "%u"
+#  define SSZF "%d"
+# endif
 #endif
 
 #endif