]> git.proxmox.com Git - mirror_edk2.git/blobdiff - UnixPkg/Include/Common/UnixInclude.h
2nd wave of r11105 checkin.2nd wave of r11105 checkin.
[mirror_edk2.git] / UnixPkg / Include / Common / UnixInclude.h
index cc02353cd24ced54ddbfc9731bbf1a588e6b77dd..8cfa2a3deb766fdcd271a8189dfea2c56e3c57f7 100644 (file)
@@ -1,7 +1,7 @@
 /*++\r
 \r
 Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r
-Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+Portions copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -20,21 +20,164 @@ Abstract:
 \r
 #ifndef __UNIX_INCLUDE_H__\r
 #define __UNIX_INCLUDE_H__\r
+\r
+// #include <sys/poll.h>\r
+// #include <dirent.h>\r
+\r
+//\r
+// Name mangle to prevent build errors. I.e conflicts between EFI and OS\r
+//\r
+#define NTOHL   _UNIX_EFI_NAME_MANGLE_NTOHL_\r
+#define HTONL   _UNIX_EFI_NAME_MANGLE_HTONL_\r
+#define NTOHS   _UNIX_EFI_NAME_MANGLE_NTOHS_\r
+#define HTONS   _UNIX_EFI_NAME_MANGLE_HTOHS_\r
+#define B0      _UNIX_EFI_NAME_MANGLE_B0_\r
+\r
+\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+\r
 #include <sys/types.h>\r
 #include <sys/stat.h>\r
+#include <sys/termios.h>\r
+#include <sys/time.h>\r
+\r
+#if __CYGWIN__\r
+#include <sys/dirent.h>\r
+#else\r
+#include <sys/dir.h>\r
+#endif\r
+\r
+#include <unistd.h>\r
+#include <poll.h>\r
+#include <fcntl.h>\r
+#include <time.h>\r
+#include <signal.h>\r
+#include <errno.h>\r
+#include <string.h>\r
+#include <stdlib.h>\r
+#include <sys/ioctl.h>\r
+\r
+#include <sys/socket.h>\r
+#include <netdb.h>\r
+#include <netinet/in.h>\r
+#include <net/if.h>\r
+#include <net/if_dl.h>\r
+#include <ifaddrs.h>\r
+#include <net/bpf.h>\r
 \r
 #ifdef __APPLE__\r
 #include <sys/param.h>\r
 #include <sys/mount.h>\r
+#define _XOPEN_SOURCE\r
+#ifndef _Bool\r
+  #define _Bool char // for clang debug\r
+#endif\r
 #else\r
+#include <termio.h>\r
 #include <sys/vfs.h>\r
 #endif \r
 \r
-#include <sys/poll.h>\r
-#include <dirent.h>\r
-#include <errno.h>\r
-#include <fcntl.h>\r
-#include <time.h>\r
 #include <utime.h>\r
-#include <unistd.h>\r
+\r
+#if __APPLE__\r
+//\r
+// EFI packing is not compatible witht he default OS packing for struct stat.\r
+// st_size is 64-bit but starts on a 32-bit offset in the structure. The compiler\r
+// flags used to produce compatible EFI images, break struct stat\r
+//\r
+#ifdef MDE_CPU_IA32\r
+#pragma pack(4)\r
 #endif\r
+\r
+#if defined(__DARWIN_64_BIT_INO_T)\r
+\r
+\r
+typedef struct {\r
+  UINTN        tv_sec;         /* seconds */\r
+       UINTN   tv_nsec;        /* and nanoseconds */\r
+} EFI_timespec;\r
+\r
+\r
+\r
+typedef struct stat_fix { \\r
+       dev_t           st_dev;                 /* [XSI] ID of device containing file */ \r
+       mode_t          st_mode;                /* [XSI] Mode of file (see below) */ \r
+       nlink_t         st_nlink;               /* [XSI] Number of hard links */ \r
+       __darwin_ino64_t st_ino;                /* [XSI] File serial number */ \r
+       uid_t           st_uid;                 /* [XSI] User ID of the file */ \r
+       gid_t           st_gid;                 /* [XSI] Group ID of the file */ \r
+       dev_t           st_rdev;                /* [XSI] Device ID */ \r
+\r
+  // clang for X64 ABI follows Windows and a long is 32-bits\r
+  // this breaks system inlcude files so that is why we need\r
+  // to redefine timespec as EFI_timespec \r
+  EFI_timespec  st_atimespec;\r
+  EFI_timespec  st_mtimespec;\r
+  EFI_timespec  st_ctimespec;\r
+  EFI_timespec  st_birthtimespec;\r
+\r
+       off_t           st_size;                /* [XSI] file size, in bytes */ \r
+       blkcnt_t        st_blocks;              /* [XSI] blocks allocated for file */ \r
+       blksize_t       st_blksize;             /* [XSI] optimal blocksize for I/O */ \r
+       __uint32_t      st_flags;               /* user defined flags for file */ \r
+       __uint32_t      st_gen;                 /* file generation number */ \r
+       __int32_t       st_lspare;              /* RESERVED: DO NOT USE! */ \r
+       __int64_t       st_qspare[2];           /* RESERVED: DO NOT USE! */ \r
+} STAT_FIX;\r
+\r
+#else /* !__DARWIN_64_BIT_INO_T */\r
+\r
+typedef struct stat_fix {\r
+       dev_t           st_dev;         /* [XSI] ID of device containing file */\r
+       ino_t           st_ino;         /* [XSI] File serial number */\r
+       mode_t          st_mode;        /* [XSI] Mode of file (see below) */\r
+       nlink_t         st_nlink;       /* [XSI] Number of hard links */\r
+       uid_t           st_uid;         /* [XSI] User ID of the file */\r
+       gid_t           st_gid;         /* [XSI] Group ID of the file */\r
+       dev_t           st_rdev;        /* [XSI] Device ID */\r
+#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)\r
+       struct  timespec st_atimespec;  /* time of last access */\r
+       struct  timespec st_mtimespec;  /* time of last data modification */\r
+       struct  timespec st_ctimespec;  /* time of last status change */\r
+#else\r
+       time_t          st_atime;       /* [XSI] Time of last access */\r
+       long            st_atimensec;   /* nsec of last access */\r
+       time_t          st_mtime;       /* [XSI] Last data modification time */\r
+       long            st_mtimensec;   /* last data modification nsec */\r
+       time_t          st_ctime;       /* [XSI] Time of last status change */\r
+       long            st_ctimensec;   /* nsec of last status change */\r
+#endif\r
+       off_t           st_size;        /* [XSI] file size, in bytes */\r
+       blkcnt_t        st_blocks;      /* [XSI] blocks allocated for file */\r
+       blksize_t       st_blksize;     /* [XSI] optimal blocksize for I/O */\r
+       __uint32_t      st_flags;       /* user defined flags for file */\r
+       __uint32_t      st_gen;         /* file generation number */\r
+       __int32_t       st_lspare;      /* RESERVED: DO NOT USE! */\r
+       __int64_t       st_qspare[2];   /* RESERVED: DO NOT USE! */\r
+} STAT_FIX;\r
+\r
+#endif\r
+\r
+#ifdef MDE_CPU_IA32\r
+#pragma pack(4)\r
+#endif\r
+\r
+#else \r
+\r
+  typedef struct stat STAT_FIX;\r
+\r
+#endif\r
+\r
+//\r
+// Undo name mangling\r
+//\r
+#undef NTOHL\r
+#undef HTONL\r
+#undef NTOHS\r
+#undef HTONS\r
+#undef B0\r
+\r
+\r
+#endif\r
+\r