Code

Merge branch 'qq/maint'
[git.git] / compat / mingw.h
index 95a08b4128d6d5a2017aca18b9b6de59dcbc12ea..6bc049ad993cb95885fbb936c67a3b7c986e56eb 100644 (file)
@@ -59,9 +59,6 @@ struct itimerval {
 };
 #define ITIMER_REAL 0
 
-#define st_blocks st_size/512  /* will be cleaned up later */
-#define lstat stat
-
 /*
  * trivial stubs
  */
@@ -122,14 +119,11 @@ static inline int waitpid(pid_t pid, unsigned *status, unsigned options)
        return -1;
 }
 
-
-static inline int pipe(int filedes[2])
-{ return _pipe(filedes, 8192, 0); }
-
 /*
  * implementations of missing functions
  */
 
+int pipe(int filedes[2]);
 unsigned int sleep (unsigned int seconds);
 int mkstemp(char *template);
 int gettimeofday(struct timeval *tv, void *tz);
@@ -151,6 +145,54 @@ int mingw_open (const char *filename, int oflags, ...);
 char *mingw_getcwd(char *pointer, int len);
 #define getcwd mingw_getcwd
 
+char *mingw_getenv(const char *name);
+#define getenv mingw_getenv
+
+struct hostent *mingw_gethostbyname(const char *host);
+#define gethostbyname mingw_gethostbyname
+
+int mingw_socket(int domain, int type, int protocol);
+#define socket mingw_socket
+
+int mingw_connect(int sockfd, struct sockaddr *sa, size_t sz);
+#define connect mingw_connect
+
+int mingw_rename(const char*, const char*);
+#define rename mingw_rename
+
+/* Use mingw_lstat() instead of lstat()/stat() and
+ * mingw_fstat() instead of fstat() on Windows.
+ * struct stat is redefined because it lacks the st_blocks member.
+ */
+struct mingw_stat {
+       unsigned st_mode;
+       time_t st_mtime, st_atime, st_ctime;
+       unsigned st_dev, st_ino, st_uid, st_gid;
+       size_t st_size;
+       size_t st_blocks;
+};
+int mingw_lstat(const char *file_name, struct mingw_stat *buf);
+int mingw_fstat(int fd, struct mingw_stat *buf);
+#define fstat mingw_fstat
+#define lstat mingw_lstat
+#define stat mingw_stat
+static inline int mingw_stat(const char *file_name, struct mingw_stat *buf)
+{ return mingw_lstat(file_name, buf); }
+
+int mingw_utime(const char *file_name, const struct utimbuf *times);
+#define utime mingw_utime
+
+pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **env);
+void mingw_execvp(const char *cmd, char *const *argv);
+#define execvp mingw_execvp
+
+static inline unsigned int git_ntohl(unsigned int x)
+{ return (unsigned int)ntohl(x); }
+#define ntohl git_ntohl
+
+sig_handler_t mingw_signal(int sig, sig_handler_t handler);
+#define signal mingw_signal
+
 /*
  * git specific compatibility
  */
@@ -158,3 +200,12 @@ char *mingw_getcwd(char *pointer, int len);
 #define has_dos_drive_prefix(path) (isalpha(*(path)) && (path)[1] == ':')
 #define is_dir_sep(c) ((c) == '/' || (c) == '\\')
 #define PATH_SEP ';'
+#define PRIuMAX "I64u"
+
+/*
+ * helpers
+ */
+
+char **copy_environ(void);
+void free_environ(char **env);
+char **env_setenv(char **env, const char *name);