Fix W32 gauger C bindings - quote arguments
[oweals/gnunet.git] / src / include / plibc.h
index 06db48c04a0c82b26253bda4bca98d001e37aeb7..1cb84e6b7f5f3e2cef9f7bd1ddf6d670b7b0dc5e 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of PlibC.
-     (C) 2005, 2006, 2007, 2008, 2009 Nils Durner (and other contributing authors)
+     (C) 2005, 2006, 2007, 2008, 2009, 2010 Nils Durner (and other contributing authors)
 
           This library is free software; you can redistribute it and/or
           modify it under the terms of the GNU Lesser General Public
@@ -22,7 +22,7 @@
  * @brief PlibC header
  * @attention This file is usually not installed under Unix,
  *            so ship it with your application
- * @version $Revision: 45 $
+ * @version $Revision: 84 $
  */
 
 #ifndef _PLIBC_H_
@@ -50,8 +50,9 @@ extern "C" {
   #include "langinfo.h"
 #endif
 
+#include <ws2tcpip.h>
 #include <windows.h>
-#include <Ws2tcpip.h>
+#include <sys/types.h>
 #include <time.h>
 #include <stdio.h>
 #include <sys/types.h>
@@ -69,13 +70,7 @@ extern "C" {
 /* Convert LARGE_INTEGER to double */
 #define Li2Double(x) ((double)((x).HighPart) * 4.294967296E9 + \
   (double)((x).LowPart))
-
-#define socklen_t int
-#define ssize_t int
-#define off_t int
-#define int64_t long long
-#define int32_t long
-
+#ifndef __MINGW64__
 struct stat64
 {
     _dev_t st_dev;
@@ -90,9 +85,20 @@ struct stat64
     __time64_t st_mtime;
     __time64_t st_ctime;
 };
+#endif
+typedef unsigned int sa_family_t;
+
+struct sockaddr_un {
+  short sun_family; /*AF_UNIX*/
+  char sun_path[108]; /*path name */
+};
 
 #ifndef pid_t
-       #define pid_t int
+  #define pid_t DWORD
+#endif
+
+#ifndef error_t
+  #define error_t int
 #endif
 
 #ifndef WEXITSTATUS
@@ -103,6 +109,12 @@ struct stat64
   #define MSG_DONTWAIT 0
 #endif
 
+enum
+{
+  _SC_PAGESIZE = 30,
+  _SC_PAGE_SIZE = 30
+};
+
 /* Thanks to the Cygwin project */
 #define ENOCSI 43      /* No CSI structure available */
 #define EL2HLT 44      /* Level 2 halted */
@@ -214,8 +226,13 @@ struct stat64
 #define MAP_SHARED  0x1
 #define MAP_PRIVATE 0x2 /* unsupported */
 #define MAP_FIXED   0x10
+#define MAP_ANONYMOUS 0x20 /* unsupported */
 #define MAP_FAILED  ((void *)-1)
 
+#define MS_ASYNC        1       /* sync memory asynchronously */
+#define MS_INVALIDATE   2       /* invalidate the caches */
+#define MS_SYNC         4       /* synchronous memory sync */
+
 struct statfs
 {
   long f_type;                  /* type of filesystem (see below) */
@@ -319,17 +336,29 @@ typedef struct
 #define SetErrnoFromWinError(e) _SetErrnoFromWinError(e, __FILE__, __LINE__)
 
 BOOL _plibc_CreateShortcut(const char *pszSrc, const char *pszDest);
+BOOL _plibc_CreateShortcutW(const wchar_t *pwszSrc, const wchar_t *pwszDest);
 BOOL _plibc_DereferenceShortcut(char *pszShortcut);
+BOOL _plibc_DereferenceShortcutW(wchar_t *pwszShortcut);
 char *plibc_ChooseDir(char *pszTitle, unsigned long ulFlags);
+wchar_t *plibc_ChooseDirW(wchar_t *pwszTitle, unsigned long ulFlags);
 char *plibc_ChooseFile(char *pszTitle, unsigned long ulFlags);
-long QueryRegistry(HKEY hMainKey, char *pszKey, char *pszSubKey,
+wchar_t *plibc_ChooseFileW(wchar_t *pwszTitle, unsigned long ulFlags);
+
+long QueryRegistry(HKEY hMainKey, const char *pszKey, const char *pszSubKey,
               char *pszBuffer, long *pdLength);
+long QueryRegistryW(HKEY hMainKey, const wchar_t *pszKey, const wchar_t *pszSubKey,
+              wchar_t *pszBuffer, long *pdLength);
 
-BOOL __win_IsHandleMarkedAsBlocking(SOCKET hHandle);
-void __win_SetHandleBlockingMode(SOCKET s, BOOL bBlocking);
-void __win_DiscardHandleBlockingMode(SOCKET s);
+BOOL __win_IsHandleMarkedAsBlocking(int hHandle);
+void __win_SetHandleBlockingMode(int s, BOOL bBlocking);
+void __win_DiscardHandleBlockingMode(int s);
 int _win_isSocketValid(int s);
 int plibc_conv_to_win_path(const char *pszUnix, char *pszWindows);
+int plibc_conv_to_win_pathw(const wchar_t *pszUnix, wchar_t *pwszWindows);
+
+int plibc_conv_to_win_pathwconv(const char *pszUnix, wchar_t *pwszWindows);
+int plibc_conv_to_win_pathwconv_ex(const char *pszUnix, wchar_t *pszWindows, int derefLinks);
+
 unsigned plibc_get_handle_count();
 
 typedef void (*TPanicProc) (int, char *);
@@ -348,18 +377,23 @@ const char *hstrerror(int err);
 int mkstemp(char *tmplate);
 char *strptime (const char *buf, const char *format, struct tm *tm);
 const char *inet_ntop(int af, const void *src, char *dst, size_t size);
+struct tm *gmtime_r(const time_t *clock, struct tm *result);
 
 int plibc_init(char *pszOrg, char *pszApp);
+int plibc_init_utf8(char *pszOrg, char *pszApp, int utf8_mode);
 void plibc_shutdown();
 int plibc_initialized();
-int plibc_conv_to_win_path_ex(const char *pszUnix, char *pszWindows, int derefLinks);
+
 void _SetErrnoFromWinError(long lWinError, char *pszCaller, int iLine);
 void SetErrnoFromWinsockError(long lWinError);
 void SetHErrnoFromWinError(long lWinError);
 void SetErrnoFromHRESULT(HRESULT hRes);
 int GetErrnoFromWinsockError(long lWinError);
 FILE *_win_fopen(const char *filename, const char *mode);
+int _win_fclose(FILE *);
 DIR *_win_opendir(const char *dirname);
+struct dirent *_win_readdir(DIR *dirp);
+int _win_closedir(DIR *dirp);
 int _win_open(const char *filename, int oflag, ...);
 #ifdef ENABLE_NLS
 char *_win_bindtextdomain(const char *domainname, const char *dirname);
@@ -384,6 +418,7 @@ int _win_remove(const char *path);
 int _win_rename(const char *oldname, const char *newname);
 int _win_stat(const char *path, struct stat *buffer);
 int _win_stat64(const char *path, struct stat64 *buffer);
+long _win_sysconf(int name);
 int _win_unlink(const char *filename);
 int _win_write(int fildes, const void *buf, size_t nbyte);
 int _win_read(int fildes, void *buf, size_t nbyte);
@@ -392,47 +427,78 @@ size_t _win_fread( void *buffer, size_t size, size_t count, FILE *stream );
 int _win_symlink(const char *path1, const char *path2);
 void *_win_mmap(void *start, size_t len, int access, int flags, int fd,
                 unsigned long long offset);
+int _win_msync(void *start, size_t length, int flags);
 int _win_munmap(void *start, size_t length);
 int _win_lstat(const char *path, struct stat *buf);
 int _win_lstat64(const char *path, struct stat64 *buf);
 int _win_readlink(const char *path, char *buf, size_t bufsize);
-int _win_accept(SOCKET s, struct sockaddr *addr, int *addrlen);
+int _win_accept(int s, struct sockaddr *addr, int *addrlen);
+
 int _win_printf(const char *format,...);
+int _win_wprintf(const wchar_t *format, ...);
+
 int _win_fprintf(FILE *f,const char *format,...);
+int _win_fwprintf(FILE *f,const wchar_t *format, ...);
+
 int _win_vprintf(const char *format, va_list ap);
+int _win_vfwprintf(FILE *stream, const wchar_t *format, va_list arg_ptr);
+
 int _win_vfprintf(FILE *stream, const char *format, va_list arg_ptr);
+int _win_vwprintf(const wchar_t *format, va_list ap);
+
 int _win_vsprintf(char *dest,const char *format, va_list arg_ptr);
+int _win_vswprintf(wchar_t *dest, const wchar_t *format, va_list arg_ptr);
+
 int _win_vsnprintf(char* str, size_t size, const char *format, va_list arg_ptr);
+int _win_vsnwprintf(wchar_t* wstr, size_t size, const wchar_t *format, va_list arg_ptr);
+
 int _win_snprintf(char *str,size_t size,const char *format,...);
+int _win_snwprintf(wchar_t *str, size_t size, const wchar_t *format, ...);
+
 int _win_sprintf(char *dest,const char *format,...);
+int _win_swprintf(wchar_t *dest, const wchar_t *format, ...);
+
 int _win_vsscanf(const char* str, const char* format, va_list arg_ptr);
+int _win_vswscanf(const wchar_t* wstr, const wchar_t* format, va_list arg_ptr);
+
 int _win_sscanf(const char *str, const char *format, ...);
+int _win_swscanf(const wchar_t *wstr, const wchar_t *format, ...);
+
 int _win_vfscanf(FILE *stream, const char *format, va_list arg_ptr);
+int _win_vfwscanf(FILE *stream, const wchar_t *format, va_list arg_ptr);
+
 int _win_vscanf(const char *format, va_list arg_ptr);
+int _win_vwscanf(const wchar_t *format, va_list arg_ptr);
+
 int _win_scanf(const char *format, ...);
+int _win_wscanf(const wchar_t *format, ...);
+
 int _win_fscanf(FILE *stream, const char *format, ...);
+int _win_fwscanf(FILE *stream, const wchar_t *format, ...);
+
+
 pid_t _win_waitpid(pid_t pid, int *stat_loc, int options);
-int _win_bind(SOCKET s, const struct sockaddr *name, int namelen);
-int _win_connect(SOCKET s,const struct sockaddr *name, int namelen);
-int _win_getpeername(SOCKET s, struct sockaddr *name,
+int _win_bind(int s, const struct sockaddr *name, int namelen);
+int _win_connect(int s,const struct sockaddr *name, int namelen);
+int _win_getpeername(int s, struct sockaddr *name,
                 int *namelen);
-int _win_getsockname(SOCKET s, struct sockaddr *name,
+int _win_getsockname(int s, struct sockaddr *name,
                 int *namelen);
-int _win_getsockopt(SOCKET s, int level, int optname, char *optval,
+int _win_getsockopt(int s, int level, int optname, char *optval,
                                int *optlen);
-int _win_listen(SOCKET s, int backlog);
-int _win_recv(SOCKET s, char *buf, int len, int flags);
-int _win_recvfrom(SOCKET s, void *buf, int len, int flags,
+int _win_listen(int s, int backlog);
+int _win_recv(int s, char *buf, int len, int flags);
+int _win_recvfrom(int s, void *buf, int len, int flags,
              struct sockaddr *from, int *fromlen);
 int _win_select(int max_fd, fd_set * rfds, fd_set * wfds, fd_set * efds,
                 const struct timeval *tv);
-int _win_send(SOCKET s, const char *buf, int len, int flags);
-int _win_sendto(SOCKET s, const char *buf, int len, int flags,
+int _win_send(int s, const char *buf, int len, int flags);
+int _win_sendto(int s, const char *buf, int len, int flags,
                 const struct sockaddr *to, int tolen);
-int _win_setsockopt(SOCKET s, int level, int optname, const void *optval,
+int _win_setsockopt(int s, int level, int optname, const void *optval,
                     int optlen);
-int _win_shutdown(SOCKET s, int how);
-SOCKET _win_socket(int af, int type, int protocol);
+int _win_shutdown(int s, int how);
+int _win_socket(int af, int type, int protocol);
 struct hostent *_win_gethostbyaddr(const char *addr, int len, int type);
 struct hostent *_win_gethostbyname(const char *name);
 struct hostent *gethostbyname2(const char *name, int af);
@@ -447,17 +513,20 @@ char *strndup (const char *s, size_t n);
 size_t strnlen (const char *str, size_t maxlen);
 #endif
 char *stpcpy(char *dest, const char *src);
-
+char *strcasestr(const char *haystack_start, const char *needle_start);
+#ifndef __MINGW64__
 #define strcasecmp(a, b) stricmp(a, b)
+#define wcscasecmp(a, b) wcsicmp(a, b)
 #define strncasecmp(a, b, c) strnicmp(a, b, c)
-
+#define wcsncasecmp(a, b, c) wcsnicmp(a, b, c)
+#endif
 #endif /* WINDOWS */
 
 #ifndef WINDOWS
  #define DIR_SEPARATOR '/'
  #define DIR_SEPARATOR_STR "/"
- #define PATH_SEPARATOR ';'
- #define PATH_SEPARATOR_STR ";"
+ #define PATH_SEPARATOR ':'
+ #define PATH_SEPARATOR_STR ":"
  #define NEWLINE "\n"
 
 #ifdef ENABLE_NLS
@@ -468,8 +537,11 @@ char *stpcpy(char *dest, const char *src);
  #define CTIME_R(c, b) ctime_r(c, b)
  #undef FOPEN
  #define FOPEN(f, m) fopen(f, m)
+ #define FCLOSE(f) fclose(f)
  #define FTRUNCATE(f, l) ftruncate(f, l)
  #define OPENDIR(d) opendir(d)
+ #define CLOSEDIR(d) closedir(d)
+ #define READDIR(d) readdir(d)
  #define OPEN open
  #define CHDIR(d) chdir(d)
  #define CLOSE(f) close(f)
@@ -484,6 +556,7 @@ char *stpcpy(char *dest, const char *src);
  #define RENAME(o, n) rename(o, n)
  #define STAT(p, b) stat(p, b)
  #define STAT64(p, b) stat64(p, b)
+ #define SYSCONF(n) sysconf(n)
  #define UNLINK(f) unlink(f)
  #define WRITE(f, b, n) write(f, b, n)
  #define READ(f, b, n) read(f, b, n)
@@ -491,6 +564,8 @@ char *stpcpy(char *dest, const char *src);
  #define GN_FWRITE(b, s, c, f) fwrite(b, s, c, f)
  #define SYMLINK(a, b) symlink(a, b)
  #define MMAP(s, l, p, f, d, o) mmap(s, l, p, f, d, o)
+ #define MKFIFO(p, m) mkfifo(p, m)
+ #define MSYNC(s, l, f) msync(s, l, f)
  #define MUNMAP(s, l) munmap(s, l)
  #define STRERROR(i) strerror(i)
  #define RANDOM() random()
@@ -549,8 +624,8 @@ char *stpcpy(char *dest, const char *src);
 #else
  #define DIR_SEPARATOR '\\'
  #define DIR_SEPARATOR_STR "\\"
- #define PATH_SEPARATOR ':'
- #define PATH_SEPARATOR_STR ":"
+ #define PATH_SEPARATOR ';'
+ #define PATH_SEPARATOR_STR ";"
  #define NEWLINE "\r\n"
 
 #ifdef ENABLE_NLS
@@ -560,8 +635,11 @@ char *stpcpy(char *dest, const char *src);
  #define PLIBC_CTIME(c) _win_ctime(c)
  #define CTIME_R(c, b) _win_ctime_r(c, b)
  #define FOPEN(f, m) _win_fopen(f, m)
+ #define FCLOSE(f) _win_fclose(f)
  #define FTRUNCATE(f, l) _win_ftruncate(f, l)
  #define OPENDIR(d) _win_opendir(d)
+ #define CLOSEDIR(d) _win_closedir(d)
+ #define READDIR(d) _win_readdir(d)
  #define OPEN _win_open
  #define CHDIR(d) _win_chdir(d)
  #define CLOSE(f) _win_close(f)
@@ -578,6 +656,7 @@ char *stpcpy(char *dest, const char *src);
  #define RENAME(o, n) _win_rename(o, n)
  #define STAT(p, b) _win_stat(p, b)
  #define STAT64(p, b) _win_stat64(p, b)
+ #define SYSCONF(n) _win_sysconf(n)
  #define UNLINK(f) _win_unlink(f)
  #define WRITE(f, b, n) _win_write(f, b, n)
  #define READ(f, b, n) _win_read(f, b, n)
@@ -585,6 +664,8 @@ char *stpcpy(char *dest, const char *src);
  #define GN_FWRITE(b, s, c, f) _win_fwrite(b, s, c, f)
  #define SYMLINK(a, b) _win_symlink(a, b)
  #define MMAP(s, l, p, f, d, o) _win_mmap(s, l, p, f, d, o)
+ #define MKFIFO(p, m) _win_mkfifo(p, m)
+ #define MSYNC(s, l, f) _win_msync(s, l, f)
  #define MUNMAP(s, l) _win_munmap(s, l)
  #define STRERROR(i) _win_strerror(i)
  #define READLINK(p, b, s) _win_readlink(p, b, s)