diff --git a/LibZipSharp.UnitTest/LibZipSharp.UnitTest.csproj b/LibZipSharp.UnitTest/LibZipSharp.UnitTest.csproj index 2d18243..be5bb1d 100644 --- a/LibZipSharp.UnitTest/LibZipSharp.UnitTest.csproj +++ b/LibZipSharp.UnitTest/LibZipSharp.UnitTest.csproj @@ -18,7 +18,7 @@ - + diff --git a/LibZipSharp.props b/LibZipSharp.props index d3fa9ce..26196d9 100644 --- a/LibZipSharp.props +++ b/LibZipSharp.props @@ -3,6 +3,7 @@ <_LibZipSharpNugetVersion>2.0.0 <_NativeBuildDir>$(MSBuildThisFileDirectory)lzsbuild <_ExternalDir>$(MSBuildThisFileDirectory)external + <_MonoPosixNugetVersion>7.0.0-alpha.21276.2 false diff --git a/LibZipSharp/Mono.Posix/Mono.Unix.Native/Errno.cs b/LibZipSharp/Mono.Posix/Mono.Unix.Native/Errno.cs deleted file mode 100644 index f43317d..0000000 --- a/LibZipSharp/Mono.Posix/Mono.Unix.Native/Errno.cs +++ /dev/null @@ -1,194 +0,0 @@ -// -// Errno.cs -// -// Authors: -// Jonathan Pryor (jonpryor@vt.edu) -// -// (C) 2004-2006 Jonathan Pryor -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// -using System; - -namespace Mono.Unix.Native -{ - [Map] - enum Errno : int - { - // errors & their values liberally copied from - // FC2 /usr/include/asm/errno.h - - EPERM = 1, // Operation not permitted - ENOENT = 2, // No such file or directory - ESRCH = 3, // No such process - EINTR = 4, // Interrupted system call - EIO = 5, // I/O error - ENXIO = 6, // No such device or address - E2BIG = 7, // Arg list too long - ENOEXEC = 8, // Exec format error - EBADF = 9, // Bad file number - ECHILD = 10, // No child processes - EAGAIN = 11, // Try again - ENOMEM = 12, // Out of memory - EACCES = 13, // Permission denied - EFAULT = 14, // Bad address - ENOTBLK = 15, // Block device required - EBUSY = 16, // Device or resource busy - EEXIST = 17, // File exists - EXDEV = 18, // Cross-device link - ENODEV = 19, // No such device - ENOTDIR = 20, // Not a directory - EISDIR = 21, // Is a directory - EINVAL = 22, // Invalid argument - ENFILE = 23, // File table overflow - EMFILE = 24, // Too many open files - ENOTTY = 25, // Not a typewriter - ETXTBSY = 26, // Text file busy - EFBIG = 27, // File too large - ENOSPC = 28, // No space left on device - ESPIPE = 29, // Illegal seek - EROFS = 30, // Read-only file system - EMLINK = 31, // Too many links - EPIPE = 32, // Broken pipe - EDOM = 33, // Math argument out of domain of func - ERANGE = 34, // Math result not representable - EDEADLK = 35, // Resource deadlock would occur - ENAMETOOLONG = 36, // File name too long - ENOLCK = 37, // No record locks available - ENOSYS = 38, // Function not implemented - ENOTEMPTY = 39, // Directory not empty - ELOOP = 40, // Too many symbolic links encountered - EWOULDBLOCK = EAGAIN, // Operation would block - ENOMSG = 42, // No message of desired type - EIDRM = 43, // Identifier removed - ECHRNG = 44, // Channel number out of range - EL2NSYNC = 45, // Level 2 not synchronized - EL3HLT = 46, // Level 3 halted - EL3RST = 47, // Level 3 reset - ELNRNG = 48, // Link number out of range - EUNATCH = 49, // Protocol driver not attached - ENOCSI = 50, // No CSI structure available - EL2HLT = 51, // Level 2 halted - EBADE = 52, // Invalid exchange - EBADR = 53, // Invalid request descriptor - EXFULL = 54, // Exchange full - ENOANO = 55, // No anode - EBADRQC = 56, // Invalid request code - EBADSLT = 57, // Invalid slot - - EDEADLOCK = EDEADLK, - - EBFONT = 59, // Bad font file format - ENOSTR = 60, // Device not a stream - ENODATA = 61, // No data available - ETIME = 62, // Timer expired - ENOSR = 63, // Out of streams resources - ENONET = 64, // Machine is not on the network - ENOPKG = 65, // Package not installed - EREMOTE = 66, // Object is remote - ENOLINK = 67, // Link has been severed - EADV = 68, // Advertise error - ESRMNT = 69, // Srmount error - ECOMM = 70, // Communication error on send - EPROTO = 71, // Protocol error - EMULTIHOP = 72, // Multihop attempted - EDOTDOT = 73, // RFS specific error - EBADMSG = 74, // Not a data message - EOVERFLOW = 75, // Value too large for defined data type - ENOTUNIQ = 76, // Name not unique on network - EBADFD = 77, // File descriptor in bad state - EREMCHG = 78, // Remote address changed - ELIBACC = 79, // Can not access a needed shared library - ELIBBAD = 80, // Accessing a corrupted shared library - ELIBSCN = 81, // .lib section in a.out corrupted - ELIBMAX = 82, // Attempting to link in too many shared libraries - ELIBEXEC = 83, // Cannot exec a shared library directly - EILSEQ = 84, // Illegal byte sequence - ERESTART = 85, // Interrupted system call should be restarted - ESTRPIPE = 86, // Streams pipe error - EUSERS = 87, // Too many users - ENOTSOCK = 88, // Socket operation on non-socket - EDESTADDRREQ = 89, // Destination address required - EMSGSIZE = 90, // Message too long - EPROTOTYPE = 91, // Protocol wrong type for socket - ENOPROTOOPT = 92, // Protocol not available - EPROTONOSUPPORT = 93, // Protocol not supported - ESOCKTNOSUPPORT = 94, // Socket type not supported - EOPNOTSUPP = 95, // Operation not supported on transport endpoint - EPFNOSUPPORT = 96, // Protocol family not supported - EAFNOSUPPORT = 97, // Address family not supported by protocol - EADDRINUSE = 98, // Address already in use - EADDRNOTAVAIL = 99, // Cannot assign requested address - ENETDOWN = 100, // Network is down - ENETUNREACH = 101, // Network is unreachable - ENETRESET = 102, // Network dropped connection because of reset - ECONNABORTED = 103, // Software caused connection abort - ECONNRESET = 104, // Connection reset by peer - ENOBUFS = 105, // No buffer space available - EISCONN = 106, // Transport endpoint is already connected - ENOTCONN = 107, // Transport endpoint is not connected - ESHUTDOWN = 108, // Cannot send after transport endpoint shutdown - ETOOMANYREFS = 109, // Too many references: cannot splice - ETIMEDOUT = 110, // Connection timed out - ECONNREFUSED = 111, // Connection refused - EHOSTDOWN = 112, // Host is down - EHOSTUNREACH = 113, // No route to host - EALREADY = 114, // Operation already in progress - EINPROGRESS = 115, // Operation now in progress - ESTALE = 116, // Stale NFS file handle - EUCLEAN = 117, // Structure needs cleaning - ENOTNAM = 118, // Not a XENIX named type file - ENAVAIL = 119, // No XENIX semaphores available - EISNAM = 120, // Is a named type file - EREMOTEIO = 121, // Remote I/O error - EDQUOT = 122, // Quota exceeded - - ENOMEDIUM = 123, // No medium found - EMEDIUMTYPE = 124, // Wrong medium type - - ECANCELED = 125, - ENOKEY = 126, - EKEYEXPIRED = 127, - EKEYREVOKED = 128, - EKEYREJECTED = 129, - - EOWNERDEAD = 130, - ENOTRECOVERABLE = 131, - - // OS X-specific values: OS X value + 1000 - EPROCLIM = 1067, // Too many processes - EBADRPC = 1072, // RPC struct is bad - ERPCMISMATCH = 1073, // RPC version wrong - EPROGUNAVAIL = 1074, // RPC prog. not avail - EPROGMISMATCH = 1075, // Program version wrong - EPROCUNAVAIL = 1076, // Bad procedure for program - EFTYPE = 1079, // Inappropriate file type or format - EAUTH = 1080, // Authentication error - ENEEDAUTH = 1081, // Need authenticator - EPWROFF = 1082, // Device power is off - EDEVERR = 1083, // Device error, e.g. paper out - EBADEXEC = 1085, // Bad executable - EBADARCH = 1086, // Bad CPU type in executable - ESHLIBVERS = 1087, // Shared library version mismatch - EBADMACHO = 1088, // Malformed Macho file - ENOATTR = 1093, // Attribute not found - ENOPOLICY = 1103, // No such policy registered - } -} diff --git a/LibZipSharp/Mono.Posix/Mono.Unix.Native/FileNameMarshaler.cs b/LibZipSharp/Mono.Posix/Mono.Unix.Native/FileNameMarshaler.cs deleted file mode 100644 index e2093b3..0000000 --- a/LibZipSharp/Mono.Posix/Mono.Unix.Native/FileNameMarshaler.cs +++ /dev/null @@ -1,79 +0,0 @@ -// -// Mono.Unix/FileNameMarshaler.cs -// -// Authors: -// Jonathan Pryor (jonpryor@vt.edu) -// -// (C) 2005 Jonathan Pryor -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Runtime.InteropServices; -using Mono.Unix; - -namespace Mono.Unix.Native { - - class FileNameMarshaler : ICustomMarshaler { - - private static FileNameMarshaler Instance = new FileNameMarshaler (); - - public static ICustomMarshaler GetInstance (string s) - { - return Instance; - } - - public void CleanUpManagedData (object o) - { - } - - public void CleanUpNativeData (IntPtr pNativeData) - { - // Console.WriteLine ("# FileNameMarshaler.CleanUpManagedData ({0:x})", pNativeData); - UnixMarshal.FreeHeap (pNativeData); - } - - public int GetNativeDataSize () - { - return IntPtr.Size; - } - - public IntPtr MarshalManagedToNative (object obj) - { - string s = obj as string; - if (s == null) - return IntPtr.Zero; - IntPtr p = UnixMarshal.StringToHeap (s, UnixEncoding.Instance); - // Console.WriteLine ("# FileNameMarshaler.MarshalNativeToManaged for `{0}'={1:x}", s, p); - return p; - } - - public object MarshalNativeToManaged (IntPtr pNativeData) - { - string s = UnixMarshal.PtrToString (pNativeData, UnixEncoding.Instance); - // Console.WriteLine ("# FileNameMarshaler.MarshalNativeToManaged ({0:x})=`{1}'", - // pNativeData, s); - return s; - } - } -} - -// vim: noexpandtab diff --git a/LibZipSharp/Mono.Posix/Mono.Unix.Native/FilePermissions.cs b/LibZipSharp/Mono.Posix/Mono.Unix.Native/FilePermissions.cs deleted file mode 100644 index 52a4173..0000000 --- a/LibZipSharp/Mono.Posix/Mono.Unix.Native/FilePermissions.cs +++ /dev/null @@ -1,80 +0,0 @@ -// -// FilePermissions.cs -// -// Authors: -// Miguel de Icaza (miguel@novell.com) -// Jonathan Pryor (jonpryor@vt.edu) -// -// (C) 2003 Novell, Inc. -// (C) 2004-2006 Jonathan Pryor -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; - -namespace Mono.Unix.Native -{ - // mode_t - [Flags] - [Map] - [CLSCompliant (false)] - enum FilePermissions : uint - { - S_ISUID = 0x0800, // Set user ID on execution - S_ISGID = 0x0400, // Set group ID on execution - S_ISVTX = 0x0200, // Save swapped text after use (sticky). - S_IRUSR = 0x0100, // Read by owner - S_IWUSR = 0x0080, // Write by owner - S_IXUSR = 0x0040, // Execute by owner - S_IRGRP = 0x0020, // Read by group - S_IWGRP = 0x0010, // Write by group - S_IXGRP = 0x0008, // Execute by group - S_IROTH = 0x0004, // Read by other - S_IWOTH = 0x0002, // Write by other - S_IXOTH = 0x0001, // Execute by other - - S_IRWXG = (S_IRGRP | S_IWGRP | S_IXGRP), - S_IRWXU = (S_IRUSR | S_IWUSR | S_IXUSR), - S_IRWXO = (S_IROTH | S_IWOTH | S_IXOTH), - ACCESSPERMS = (S_IRWXU | S_IRWXG | S_IRWXO), // 0777 - ALLPERMS = (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO), // 07777 - DEFFILEMODE = (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH), // 0666 - - // Device types - // Why these are held in "mode_t" is beyond me... - S_IFMT = 0xF000, // Bits which determine file type - [Map (SuppressFlags = "S_IFMT")] - S_IFDIR = 0x4000, // Directory - [Map (SuppressFlags = "S_IFMT")] - S_IFCHR = 0x2000, // Character device - [Map (SuppressFlags = "S_IFMT")] - S_IFBLK = 0x6000, // Block device - [Map (SuppressFlags = "S_IFMT")] - S_IFREG = 0x8000, // Regular file - [Map (SuppressFlags = "S_IFMT")] - S_IFIFO = 0x1000, // FIFO - [Map (SuppressFlags = "S_IFMT")] - S_IFLNK = 0xA000, // Symbolic link - [Map (SuppressFlags = "S_IFMT")] - S_IFSOCK = 0xC000, // Socket - } - -} diff --git a/LibZipSharp/Mono.Posix/Mono.Unix.Native/MapAttribute.cs b/LibZipSharp/Mono.Posix/Mono.Unix.Native/MapAttribute.cs deleted file mode 100644 index e659975..0000000 --- a/LibZipSharp/Mono.Posix/Mono.Unix.Native/MapAttribute.cs +++ /dev/null @@ -1,60 +0,0 @@ -// -// MapAttribute.cs -// -// Author: -// Miguel de Icaza (miguel@gnome.org) -// -// (C) Novell, Inc. -// - -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// -using System; - -[AttributeUsage ( - AttributeTargets.Class | - AttributeTargets.Delegate | - AttributeTargets.Enum | - AttributeTargets.Field | - AttributeTargets.Struct)] -internal class MapAttribute : Attribute { - private string nativeType; - private string suppressFlags; - - public MapAttribute () - { - } - - public MapAttribute (string nativeType) - { - this.nativeType = nativeType; - } - - public string NativeType { - get {return nativeType;} - } - - public string SuppressFlags { - get {return suppressFlags;} - set {suppressFlags = value;} - } -} - diff --git a/LibZipSharp/Mono.Posix/Mono.Unix.Native/NativeConvert.generated.cs b/LibZipSharp/Mono.Posix/Mono.Unix.Native/NativeConvert.generated.cs deleted file mode 100644 index e4c92d7..0000000 --- a/LibZipSharp/Mono.Posix/Mono.Unix.Native/NativeConvert.generated.cs +++ /dev/null @@ -1,65 +0,0 @@ - -using System; -using System.Runtime.InteropServices; - -namespace Mono.Unix.Native -{ - sealed partial class NativeConvert - { - const string LIB = "MonoPosixHelper"; - - static void ThrowArgumentException (object value) - { - throw new ArgumentOutOfRangeException ("value", value, "Current platform doesn't support this value."); - } - - [DllImport (LIB, EntryPoint = "Mono_Posix_FromErrno")] - private static extern int FromErrno (Errno value, out Int32 rval); - - public static bool TryFromErrno (Errno value, out Int32 rval) - { - return FromErrno (value, out rval) == 0; - } - - public static Int32 FromErrno (Errno value) - { - Int32 rval; - if (FromErrno (value, out rval) == -1) - ThrowArgumentException (value); - return rval; - } - - [DllImport (LIB, EntryPoint = "Mono_Posix_ToErrno")] - private static extern int ToErrno (Int32 value, out Errno rval); - - public static bool TryToErrno (Int32 value, out Errno rval) - { - return ToErrno (value, out rval) == 0; - } - - public static Errno ToErrno (Int32 value) - { - Errno rval; - if (ToErrno (value, out rval) == -1) - ThrowArgumentException (value); - return rval; - } - - [DllImport (LIB, EntryPoint = "Mono_Posix_FromFilePermissions")] - private static extern int FromFilePermissions (FilePermissions value, out UInt32 rval); - - public static bool TryFromFilePermissions (FilePermissions value, out UInt32 rval) - { - return FromFilePermissions (value, out rval) == 0; - } - - public static UInt32 FromFilePermissions (FilePermissions value) - { - UInt32 rval; - if (FromFilePermissions (value, out rval) == -1) - ThrowArgumentException (value); - return rval; - } - - } -} diff --git a/LibZipSharp/Mono.Posix/Mono.Unix.Native/Stat.cs b/LibZipSharp/Mono.Posix/Mono.Unix.Native/Stat.cs deleted file mode 100644 index e6340dd..0000000 --- a/LibZipSharp/Mono.Posix/Mono.Unix.Native/Stat.cs +++ /dev/null @@ -1,184 +0,0 @@ -// -// Stat.cs -// -// Mono.Unix/Syscall.cs -// -// Authors: -// Miguel de Icaza (miguel@novell.com) -// Jonathan Pryor (jonpryor@vt.edu) -// -// (C) 2003 Novell, Inc. -// (C) 2004-2006 Jonathan Pryor -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; - -namespace Mono.Unix.Native -{ - // Use manually written To/From methods to handle fields st_atime_nsec etc. - struct Stat - : IEquatable - { - [CLSCompliant (false)] - [dev_t] - public ulong st_dev; // device - [CLSCompliant (false)] - [ino_t] - public ulong st_ino; // inode - [CLSCompliant (false)] - public FilePermissions st_mode; // protection - [NonSerialized] -#pragma warning disable 169 - private uint _padding_; // padding for structure alignment -#pragma warning restore 169 - [CLSCompliant (false)] - [nlink_t] - public ulong st_nlink; // number of hard links - [CLSCompliant (false)] - [uid_t] - public uint st_uid; // user ID of owner - [CLSCompliant (false)] - [gid_t] - public uint st_gid; // group ID of owner - [CLSCompliant (false)] - [dev_t] - public ulong st_rdev; // device type (if inode device) - [off_t] - public long st_size; // total size, in bytes - [blksize_t] - public long st_blksize; // blocksize for filesystem I/O - [blkcnt_t] - public long st_blocks; // number of blocks allocated - [time_t] - public long st_atime; // time of last access - [time_t] - public long st_mtime; // time of last modification - [time_t] - public long st_ctime; // time of last status change - public long st_atime_nsec; // Timespec.tv_nsec partner to st_atime - public long st_mtime_nsec; // Timespec.tv_nsec partner to st_mtime - public long st_ctime_nsec; // Timespec.tv_nsec partner to st_ctime - - public Timespec st_atim { - get { - return new Timespec { tv_sec = st_atime, tv_nsec = st_atime_nsec }; - } - set { - st_atime = value.tv_sec; - st_atime_nsec = value.tv_nsec; - } - } - - public Timespec st_mtim { - get { - return new Timespec { tv_sec = st_mtime, tv_nsec = st_mtime_nsec }; - } - set { - st_mtime = value.tv_sec; - st_mtime_nsec = value.tv_nsec; - } - } - - public Timespec st_ctim { - get { - return new Timespec { tv_sec = st_ctime, tv_nsec = st_ctime_nsec }; - } - set { - st_ctime = value.tv_sec; - st_ctime_nsec = value.tv_nsec; - } - } - - public override int GetHashCode () - { - return st_dev.GetHashCode () ^ - st_ino.GetHashCode () ^ - st_mode.GetHashCode () ^ - st_nlink.GetHashCode () ^ - st_uid.GetHashCode () ^ - st_gid.GetHashCode () ^ - st_rdev.GetHashCode () ^ - st_size.GetHashCode () ^ - st_blksize.GetHashCode () ^ - st_blocks.GetHashCode () ^ - st_atime.GetHashCode () ^ - st_mtime.GetHashCode () ^ - st_ctime.GetHashCode () ^ - st_atime_nsec.GetHashCode () ^ - st_mtime_nsec.GetHashCode () ^ - st_ctime_nsec.GetHashCode (); - } - - public override bool Equals (object obj) - { - if (obj == null || obj.GetType () != GetType ()) - return false; - Stat value = (Stat)obj; - return value.st_dev == st_dev && - value.st_ino == st_ino && - value.st_mode == st_mode && - value.st_nlink == st_nlink && - value.st_uid == st_uid && - value.st_gid == st_gid && - value.st_rdev == st_rdev && - value.st_size == st_size && - value.st_blksize == st_blksize && - value.st_blocks == st_blocks && - value.st_atime == st_atime && - value.st_mtime == st_mtime && - value.st_ctime == st_ctime && - value.st_atime_nsec == st_atime_nsec && - value.st_mtime_nsec == st_mtime_nsec && - value.st_ctime_nsec == st_ctime_nsec; - } - - public bool Equals (Stat value) - { - return value.st_dev == st_dev && - value.st_ino == st_ino && - value.st_mode == st_mode && - value.st_nlink == st_nlink && - value.st_uid == st_uid && - value.st_gid == st_gid && - value.st_rdev == st_rdev && - value.st_size == st_size && - value.st_blksize == st_blksize && - value.st_blocks == st_blocks && - value.st_atime == st_atime && - value.st_mtime == st_mtime && - value.st_ctime == st_ctime && - value.st_atime_nsec == st_atime_nsec && - value.st_mtime_nsec == st_mtime_nsec && - value.st_ctime_nsec == st_ctime_nsec; - } - - public static bool operator == (Stat lhs, Stat rhs) - { - return lhs.Equals (rhs); - } - - public static bool operator != (Stat lhs, Stat rhs) - { - return !lhs.Equals (rhs); - } - } -} diff --git a/LibZipSharp/Mono.Posix/Mono.Unix.Native/Stdlib.cs b/LibZipSharp/Mono.Posix/Mono.Unix.Native/Stdlib.cs deleted file mode 100644 index 6774545..0000000 --- a/LibZipSharp/Mono.Posix/Mono.Unix.Native/Stdlib.cs +++ /dev/null @@ -1,118 +0,0 @@ -// -// Stdlib.cs -// -// Authors: -// Jonathan Pryor (jonpryor@vt.edu) -// -// (C) 2004-2006 Jonathan Pryor -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// -using System; -using System.Runtime.InteropServices; -using System.Text; - -namespace Mono.Unix.Native -{ - class Stdlib - { - internal const string LIBC = "msvcrt"; - internal const string MPH = "MonoPosixHelper"; - - // - // - // - - private static object strerror_lock = new object (); - - [DllImport (LIBC, CallingConvention = CallingConvention.Cdecl, - SetLastError = true, EntryPoint = "strerror")] - private static extern IntPtr sys_strerror (int errnum); - - // strlen(3): - // size_t strlen(const char *s); - [CLSCompliant (false)] - [DllImport (MPH, CallingConvention = CallingConvention.Cdecl, - SetLastError = true, EntryPoint = "Mono_Posix_Stdlib_strlen")] - public static extern ulong strlen (IntPtr s); - - [CLSCompliant (false)] - public static string strerror (Errno errnum) - { - int e = NativeConvert.FromErrno (errnum); - lock (strerror_lock) { - IntPtr r = sys_strerror (e); - return UnixMarshal.PtrToString (r); - } - } - - // strerror_r(3) - // int strerror_r(int errnum, char *buf, size_t n); - [DllImport (MPH, SetLastError = true, - EntryPoint = "Mono_Posix_Syscall_strerror_r")] - private static extern int sys_strerror_r (int errnum, - [Out] StringBuilder buf, ulong n); - - public static int strerror_r (Errno errnum, StringBuilder buf, ulong n) - { - int e = NativeConvert.FromErrno (errnum); - return sys_strerror_r (e, buf, n); - } - - public static int strerror_r (Errno errnum, StringBuilder buf) - { - return strerror_r (errnum, buf, (ulong)buf.Capacity); - } - - [DllImport (LIBC, CallingConvention = CallingConvention.Cdecl)] - public static extern void free (IntPtr ptr); - - // malloc(3): - // void *malloc(size_t size); - [CLSCompliant (false)] - [DllImport (MPH, CallingConvention = CallingConvention.Cdecl, - SetLastError = true, EntryPoint = "Mono_Posix_Stdlib_malloc")] - public static extern IntPtr malloc (ulong size); - - // realloc(3): - // void *realloc(void *ptr, size_t size); - [CLSCompliant (false)] - [DllImport (MPH, CallingConvention = CallingConvention.Cdecl, - SetLastError = true, EntryPoint = "Mono_Posix_Stdlib_realloc")] - public static extern IntPtr realloc (IntPtr ptr, ulong size); - - public static Errno GetLastError () - { - int errno = Marshal.GetLastWin32Error (); - return NativeConvert.ToErrno (errno); - } - - [DllImport (MPH, CallingConvention = CallingConvention.Cdecl, - EntryPoint = "Mono_Posix_Stdlib_SetLastError")] - private static extern void SetLastError (int error); - - protected static void SetLastError (Errno error) - { - int _error = NativeConvert.FromErrno (error); - SetLastError (_error); - } - - } -} diff --git a/LibZipSharp/Mono.Posix/Mono.Unix.Native/Syscall.cs b/LibZipSharp/Mono.Posix/Mono.Unix.Native/Syscall.cs deleted file mode 100644 index 45ac6a8..0000000 --- a/LibZipSharp/Mono.Posix/Mono.Unix.Native/Syscall.cs +++ /dev/null @@ -1,163 +0,0 @@ -// -// Syscall.cs -// -// Authors: -// Miguel de Icaza (miguel@novell.com) -// Jonathan Pryor (jonpryor@vt.edu) -// -// (C) 2003 Novell, Inc. -// (C) 2004-2006 Jonathan Pryor -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Runtime.InteropServices; -using System.Text; - -namespace Mono.Unix.Native -{ - [CLSCompliant (false)] - sealed class Syscall : Stdlib - { - delegate long DoReadlinkFun (byte [] target); - - new internal const string LIBC = "libc"; - - #region Declarations - // - // -- COMPLETE - // - [DllImport (MPH, SetLastError = true, - EntryPoint = "Mono_Posix_Syscall_stat")] - public static extern int stat ( - [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))] - string file_name, out Stat buf); - - [DllImport (MPH, SetLastError = true, - EntryPoint = "Mono_Posix_Syscall_lstat")] - public static extern int lstat ( - [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))] - string file_name, out Stat buf); - #endregion - - // Helper function for readlink(string, StringBuilder) and readlinkat (int, string, StringBuilder) - static int ReadlinkIntoStringBuilder (DoReadlinkFun doReadlink, [Out] StringBuilder buf, ulong bufsiz) - { - // bufsiz > int.MaxValue can't work because StringBuilder can store only int.MaxValue chars - int bufsizInt = checked((int)bufsiz); - var target = new byte [bufsizInt]; - - var r = doReadlink (target); - if (r < 0) - return checked((int)r); - - buf.Length = 0; - var chars = UnixEncoding.Instance.GetChars (target, 0, checked((int)r)); - // Make sure that at more bufsiz chars are written - buf.Append (chars, 0, System.Math.Min (bufsizInt, chars.Length)); - if (r == bufsizInt) { - // may not have read full contents; fill 'buf' so that caller can properly check - buf.Append (new string ('\x00', bufsizInt - buf.Length)); - } - return buf.Length; - } - - // readlink(2) - // ssize_t readlink(const char *path, char *buf, size_t bufsize); - public static int readlink (string path, [Out] StringBuilder buf, ulong bufsiz) - { - return ReadlinkIntoStringBuilder (target => readlink (path, target), buf, bufsiz); - } - - public static int readlink (string path, [Out] StringBuilder buf) - { - return readlink (path, buf, (ulong)buf.Capacity); - } - - [DllImport (MPH, SetLastError = true, - EntryPoint = "Mono_Posix_Syscall_readlink")] - private static extern long readlink ( - [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))] - string path, byte [] buf, ulong bufsiz); - - public static long readlink (string path, byte [] buf) - { - return readlink (path, buf, (ulong)buf.LongLength); - } - - // chmod(2) - // int chmod(const char *path, mode_t mode); - [DllImport (LIBC, SetLastError = true, EntryPoint = "chmod")] - private static extern int sys_chmod ( - [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))] - string path, uint mode); - - public static int chmod (string path, FilePermissions mode) - { - uint _mode = NativeConvert.FromFilePermissions (mode); - return sys_chmod (path, _mode); - } - - [DllImport (MPH, SetLastError = true, - EntryPoint = "Mono_Posix_Syscall_utimes")] - private static extern int sys_utimes ( - [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))] - string filename, Timeval [] tvp); - - public static int utimes (string filename, Timeval [] tvp) - { - if (tvp != null && tvp.Length != 2) { - SetLastError (Errno.EINVAL); - return -1; - } - return sys_utimes (filename, tvp); - } - - [DllImport (MPH, SetLastError = true, - EntryPoint = "Mono_Posix_Syscall_lutimes")] - private static extern int sys_lutimes ( - [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))] - string filename, Timeval [] tvp); - - public static int lutimes (string filename, Timeval [] tvp) - { - if (tvp != null && tvp.Length != 2) { - SetLastError (Errno.EINVAL); - return -1; - } - return sys_lutimes (filename, tvp); - } - - // chown(2) - // int chown(const char *path, uid_t owner, gid_t group); - [DllImport (LIBC, SetLastError = true)] - public static extern int chown ( - [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))] - string path, uint owner, uint group); - - [DllImport (LIBC, SetLastError = true)] - public static extern int symlink ( - [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))] - string oldpath, - [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))] - string newpath); - } -} diff --git a/LibZipSharp/Mono.Posix/Mono.Unix.Native/Timespec.cs b/LibZipSharp/Mono.Posix/Mono.Unix.Native/Timespec.cs deleted file mode 100644 index d087539..0000000 --- a/LibZipSharp/Mono.Posix/Mono.Unix.Native/Timespec.cs +++ /dev/null @@ -1,72 +0,0 @@ -// -// Timespec.cs -// -// Authors: -// Miguel de Icaza (miguel@novell.com) -// Jonathan Pryor (jonpryor@vt.edu) -// -// (C) 2003 Novell, Inc. -// (C) 2004-2006 Jonathan Pryor -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; - -namespace Mono.Unix.Native -{ - [Map ("struct timespec")] - struct Timespec - : IEquatable - { - [time_t] - public long tv_sec; // Seconds. - public long tv_nsec; // Nanoseconds. - - public override int GetHashCode () - { - return tv_sec.GetHashCode () ^ tv_nsec.GetHashCode (); - } - - public override bool Equals (object obj) - { - if (obj == null || obj.GetType () != GetType ()) - return false; - Timespec value = (Timespec)obj; - return value.tv_sec == tv_sec && value.tv_nsec == tv_nsec; - } - - public bool Equals (Timespec value) - { - return value.tv_sec == tv_sec && value.tv_nsec == tv_nsec; - } - - public static bool operator == (Timespec lhs, Timespec rhs) - { - return lhs.Equals (rhs); - } - - public static bool operator != (Timespec lhs, Timespec rhs) - { - return !lhs.Equals (rhs); - } - } - -} diff --git a/LibZipSharp/Mono.Posix/Mono.Unix.Native/Timeval.cs b/LibZipSharp/Mono.Posix/Mono.Unix.Native/Timeval.cs deleted file mode 100644 index 8aa2de5..0000000 --- a/LibZipSharp/Mono.Posix/Mono.Unix.Native/Timeval.cs +++ /dev/null @@ -1,72 +0,0 @@ -// -// Timeval.cs -// -// Authors: -// Miguel de Icaza (miguel@novell.com) -// Jonathan Pryor (jonpryor@vt.edu) -// -// (C) 2003 Novell, Inc. -// (C) 2004-2006 Jonathan Pryor -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; - -namespace Mono.Unix.Native -{ - [Map ("struct timeval")] - struct Timeval - : IEquatable - { - [time_t] - public long tv_sec; // seconds - [suseconds_t] - public long tv_usec; // microseconds - - public override int GetHashCode () - { - return tv_sec.GetHashCode () ^ tv_usec.GetHashCode (); - } - - public override bool Equals (object obj) - { - if (obj == null || obj.GetType () != GetType ()) - return false; - Timeval value = (Timeval)obj; - return value.tv_sec == tv_sec && value.tv_usec == tv_usec; - } - - public bool Equals (Timeval value) - { - return value.tv_sec == tv_sec && value.tv_usec == tv_usec; - } - - public static bool operator == (Timeval lhs, Timeval rhs) - { - return lhs.Equals (rhs); - } - - public static bool operator != (Timeval lhs, Timeval rhs) - { - return !lhs.Equals (rhs); - } - } -} diff --git a/LibZipSharp/Mono.Posix/Mono.Unix.Native/TypeAttributes.cs b/LibZipSharp/Mono.Posix/Mono.Unix.Native/TypeAttributes.cs deleted file mode 100644 index 2fadc9a..0000000 --- a/LibZipSharp/Mono.Posix/Mono.Unix.Native/TypeAttributes.cs +++ /dev/null @@ -1,138 +0,0 @@ -// -// TypeAttributes.cs -// -// Author: -// Jonathan Pryor (jonpryor@vt.edu) -// -// (C) 2006 Jonathan Pryor -// - -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// -using System; - -namespace Mono.Unix.Native { - - [AttributeUsage (AttributeTargets.Field)] - internal class blkcnt_tAttribute : MapAttribute { - - public blkcnt_tAttribute () : base ("blkcnt_t") - { - } - } - - [AttributeUsage (AttributeTargets.Field)] - internal class blksize_tAttribute : MapAttribute { - - public blksize_tAttribute () : base ("blksize_t") - { - } - } - - [AttributeUsage (AttributeTargets.Field)] - internal class dev_tAttribute : MapAttribute { - - public dev_tAttribute () : base ("dev_t") - { - } - } - - [AttributeUsage (AttributeTargets.Field)] - internal class gid_tAttribute : MapAttribute { - - public gid_tAttribute () : base ("gid_t") - { - } - } - - [AttributeUsage (AttributeTargets.Field)] - internal class fsblkcnt_tAttribute : MapAttribute { - - public fsblkcnt_tAttribute () : base ("fsblkcnt_t") - { - } - } - - [AttributeUsage (AttributeTargets.Field)] - internal class fsfilcnt_tAttribute : MapAttribute { - - public fsfilcnt_tAttribute () : base ("fsfilcnt_t") - { - } - } - - [AttributeUsage (AttributeTargets.Field)] - internal class ino_tAttribute : MapAttribute { - - public ino_tAttribute () : base ("ino_t") - { - } - } - - [AttributeUsage (AttributeTargets.Field)] - internal class nlink_tAttribute : MapAttribute { - - public nlink_tAttribute () : base ("nlink_t") - { - } - } - - [AttributeUsage (AttributeTargets.Field)] - internal class off_tAttribute : MapAttribute { - - public off_tAttribute () : base ("off_t") - { - } - } - - [AttributeUsage (AttributeTargets.Field)] - internal class pid_tAttribute : MapAttribute { - - public pid_tAttribute () : base ("pid_t") - { - } - } - - [AttributeUsage (AttributeTargets.Field)] - internal class suseconds_tAttribute : MapAttribute { - - public suseconds_tAttribute () : base ("suseconds_t") - { - } - } - - [AttributeUsage (AttributeTargets.Field)] - internal class uid_tAttribute : MapAttribute { - - public uid_tAttribute () : base ("uid_t") - { - } - } - - [AttributeUsage (AttributeTargets.Field)] - internal class time_tAttribute : MapAttribute { - - public time_tAttribute () : base ("time_t") - { - } - } -} - diff --git a/LibZipSharp/Mono.Posix/Mono.Unix/UnixEncoding.cs b/LibZipSharp/Mono.Posix/Mono.Unix/UnixEncoding.cs deleted file mode 100644 index 80f043a..0000000 --- a/LibZipSharp/Mono.Posix/Mono.Unix/UnixEncoding.cs +++ /dev/null @@ -1,838 +0,0 @@ -/* - * Mono.Unix/UnixEncoding.cs - * - * Authors: - * Jonathan Pryor (jonpryor@vt.edu) - * - * Copyright (c) 2001, 2002 Southern Storm Software, Pty Ltd - * Copyright (C) 2004 Novell, Inc (http://www.novell.com) - * Copyright (C) 2005 Jonathan Pryor - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ - -namespace Mono.Unix -{ - -using System; -using System.Text; - -[Serializable] -class UnixEncoding : Encoding -{ - public static readonly Encoding Instance = new UnixEncoding (); - - public static readonly char EscapeByte = '\u0000'; - - // Constructors. - public UnixEncoding () - { - } - - // Internal version of "GetByteCount" which can handle a rolling - // state between multiple calls to this method. - private static int InternalGetByteCount (char[] chars, int index, int count, uint leftOver, bool flush) - { - // Validate the parameters. - if (chars == null) { - throw new ArgumentNullException ("chars"); - } - if (index < 0 || index > chars.Length) { - throw new ArgumentOutOfRangeException ("index", _("ArgRange_Array")); - } - if (count < 0 || count > (chars.Length - index)) { - throw new ArgumentOutOfRangeException ("count", _("ArgRange_Array")); - } - - // Determine the lengths of all characters. - char ch; - int length = 0; - uint pair = leftOver; - while (count > 0) { - ch = chars[index]; - if (pair == 0) { - if (ch == EscapeByte && count > 1) { - ++length; - ++index; - --count; - } else if (ch < '\u0080') { - ++length; - } else if (ch < '\u0800') { - length += 2; - } else if (ch >= '\uD800' && ch <= '\uDBFF') { - // This is the start of a surrogate pair. - pair = (uint)ch; - } else { - length += 3; - } - } else if (ch >= '\uDC00' && ch <= '\uDFFF') { - // We have a surrogate pair. - length += 4; - pair = 0; - } else { - // We have a surrogate start followed by a - // regular character. Technically, this is - // invalid, but we have to do something. - // We write out the surrogate start and then - // re-visit the current character again. - length += 3; - pair = 0; - continue; - } - ++index; - --count; - } - if (flush && pair != 0) { - // Flush the left-over surrogate pair start. - length += 3; - } - - // Return the final length to the caller. - return length; - } - - // Get the number of bytes needed to encode a character buffer. - public override int GetByteCount (char[] chars, int index, int count) - { - return InternalGetByteCount (chars, index, count, 0, true); - } - - // Convenience wrappers for "GetByteCount". - public override int GetByteCount (String s) - { - // Validate the parameters. - if (s == null) { - throw new ArgumentNullException ("s"); - } - - // Determine the lengths of all characters. - char ch; - int index = 0; - int count = s.Length; - int length = 0; - uint pair; - while (count > 0) { - ch = s[index++]; - if (ch == EscapeByte && count > 1) { - ++length; - ++index; - --count; - } else if (ch < '\u0080') { - ++length; - } else if (ch < '\u0800') { - length += 2; - } else if (ch >= '\uD800' && ch <= '\uDBFF' && count > 1) { - // This may be the start of a surrogate pair. - pair = (uint)(s[index]); - if (pair >= (uint)0xDC00 && pair <= (uint)0xDFFF) { - length += 4; - ++index; - --count; - } else { - length += 3; - } - } else { - length += 3; - } - --count; - } - - // Return the final length to the caller. - return length; - } - - // Internal version of "GetBytes" which can handle a rolling - // state between multiple calls to this method. - private static int InternalGetBytes (char[] chars, int charIndex, - int charCount, byte[] bytes, - int byteIndex, ref uint leftOver, - bool flush) - { - // Validate the parameters. - if (chars == null) { - throw new ArgumentNullException ("chars"); - } - if (bytes == null) { - throw new ArgumentNullException ("bytes"); - } - if (charIndex < 0 || charIndex > chars.Length) { - throw new ArgumentOutOfRangeException ("charIndex", _("ArgRange_Array")); - } - if (charCount < 0 || charCount > (chars.Length - charIndex)) { - throw new ArgumentOutOfRangeException ("charCount", _("ArgRange_Array")); - } - if (byteIndex < 0 || byteIndex > bytes.Length) { - throw new ArgumentOutOfRangeException ("byteIndex", _("ArgRange_Array")); - } - - // Convert the characters into bytes. - char ch; - int length = bytes.Length; - uint pair; - uint left = leftOver; - int posn = byteIndex; - while (charCount > 0) { - // Fetch the next UTF-16 character pair value. - ch = chars[charIndex++]; - --charCount; - if (left == 0) { - if (ch >= '\uD800' && ch <= '\uDBFF') { - // This is the start of a surrogate pair. - left = (uint)ch; - continue; - } else if (ch == EscapeByte) { - if (posn >= length) { - throw new ArgumentException (_("Arg_InsufficientSpace"), "bytes"); - } - if (--charCount >= 0) { - bytes[posn++] = (byte) chars [charIndex++]; - } - continue; - } else { - // This is a regular character. - pair = (uint)ch; - } - } else if (ch >= '\uDC00' && ch <= '\uDFFF') { - // We have a surrogate pair. - pair = ((left - (uint)0xD800) << 10) + - (((uint)ch) - (uint)0xDC00) + - (uint)0x10000; - left = 0; - } else { - // We have a surrogate start followed by a - // regular character. Technically, this is - // invalid, but we have to do something. - // We write out the surrogate start and then - // re-visit the current character again. - pair = (uint)left; - left = 0; - --charIndex; - ++charCount; - } - - // Encode the character pair value. - if (pair < (uint)0x0080) { - if (posn >= length) { - throw new ArgumentException (_("Arg_InsufficientSpace"), "bytes"); - } - bytes[posn++] = (byte)pair; - } else if (pair < (uint)0x0800) { - if ((posn + 2) > length) { - throw new ArgumentException (_("Arg_InsufficientSpace"), "bytes"); - } - bytes[posn++] = (byte)(0xC0 | (pair >> 6)); - bytes[posn++] = (byte)(0x80 | (pair & 0x3F)); - } else if (pair < (uint)0x10000) { - if ((posn + 3) > length) { - throw new ArgumentException (_("Arg_InsufficientSpace"), "bytes"); - } - bytes[posn++] = (byte)(0xE0 | (pair >> 12)); - bytes[posn++] = (byte)(0x80 | ((pair >> 6) & 0x3F)); - bytes[posn++] = (byte)(0x80 | (pair & 0x3F)); - } else { - if ((posn + 4) > length) { - throw new ArgumentException (_("Arg_InsufficientSpace"), "bytes"); - } - bytes[posn++] = (byte)(0xF0 | (pair >> 18)); - bytes[posn++] = (byte)(0x80 | ((pair >> 12) & 0x3F)); - bytes[posn++] = (byte)(0x80 | ((pair >> 6) & 0x3F)); - bytes[posn++] = (byte)(0x80 | (pair & 0x3F)); - } - } - if (flush && left != 0) { - // Flush the left-over surrogate pair start. - if ((posn + 3) > length) { - throw new ArgumentException (_("Arg_InsufficientSpace"), "bytes"); - } - bytes[posn++] = (byte)(0xE0 | (left >> 12)); - bytes[posn++] = (byte)(0x80 | ((left >> 6) & 0x3F)); - bytes[posn++] = (byte)(0x80 | (left & 0x3F)); - left = 0; - } - leftOver = left; - - // Return the final count to the caller. - return posn - byteIndex; - } - - // Get the bytes that result from encoding a character buffer. - public override int GetBytes (char[] chars, int charIndex, int charCount, - byte[] bytes, int byteIndex) - { - uint leftOver = 0; - return InternalGetBytes (chars, charIndex, charCount, bytes, byteIndex, ref leftOver, true); - } - - // Convenience wrappers for "GetBytes". - public override int GetBytes (String s, int charIndex, int charCount, - byte[] bytes, int byteIndex) - { - // Validate the parameters. - if (s == null) { - throw new ArgumentNullException ("s"); - } - if (bytes == null) { - throw new ArgumentNullException ("bytes"); - } - if (charIndex < 0 || charIndex > s.Length) { - throw new ArgumentOutOfRangeException ("charIndex", _("ArgRange_StringIndex")); - } - if (charCount < 0 || charCount > (s.Length - charIndex)) { - throw new ArgumentOutOfRangeException ("charCount", _("ArgRange_StringRange")); - } - if (byteIndex < 0 || byteIndex > bytes.Length) { - throw new ArgumentOutOfRangeException ("byteIndex", _("ArgRange_Array")); - } - - // Convert the characters into bytes. - char ch; - int length = bytes.Length; - uint pair; - int posn = byteIndex; - while (charCount > 0) { - // Fetch the next UTF-16 character pair value. - ch = s[charIndex++]; - if (ch >= '\uD800' && ch <= '\uDBFF' && charCount > 1) { - // This may be the start of a surrogate pair. - pair = (uint)(s[charIndex]); - if (pair >= (uint)0xDC00 && pair <= (uint)0xDFFF) { - pair = (pair - (uint)0xDC00) + - ((((uint)ch) - (uint)0xD800) << 10) + - (uint)0x10000; - ++charIndex; - --charCount; - } else { - pair = (uint)ch; - } - } else if (ch == EscapeByte && charCount > 1) { - if (posn >= length) { - throw new ArgumentException (_("Arg_InsufficientSpace"), "bytes"); - } - charCount -= 2; - if (charCount >= 0) { - bytes[posn++] = (byte) s [charIndex++]; - } - continue; - } else { - pair = (uint)ch; - } - --charCount; - - // Encode the character pair value. - if (pair < (uint)0x0080) { - if (posn >= length) { - throw new ArgumentException (_("Arg_InsufficientSpace"), "bytes"); - } - bytes[posn++] = (byte)pair; - } else if (pair < (uint)0x0800) { - if ((posn + 2) > length) { - throw new ArgumentException (_("Arg_InsufficientSpace"), "bytes"); - } - bytes[posn++] = (byte)(0xC0 | (pair >> 6)); - bytes[posn++] = (byte)(0x80 | (pair & 0x3F)); - } else if (pair < (uint)0x10000) { - if ((posn + 3) > length) { - throw new ArgumentException (_("Arg_InsufficientSpace"), "bytes"); - } - bytes[posn++] = (byte)(0xE0 | (pair >> 12)); - bytes[posn++] = (byte)(0x80 | ((pair >> 6) & 0x3F)); - bytes[posn++] = (byte)(0x80 | (pair & 0x3F)); - } else { - if ((posn + 4) > length) { - throw new ArgumentException (_("Arg_InsufficientSpace"), "bytes"); - } - bytes[posn++] = (byte)(0xF0 | (pair >> 18)); - bytes[posn++] = (byte)(0x80 | ((pair >> 12) & 0x3F)); - bytes[posn++] = (byte)(0x80 | ((pair >> 6) & 0x3F)); - bytes[posn++] = (byte)(0x80 | (pair & 0x3F)); - } - } - - // Return the final count to the caller. - return posn - byteIndex; - } - - // Internal version of "GetCharCount" which can handle a rolling - // state between multiple calls to this method. - private static int InternalGetCharCount (byte[] bytes, int index, int count, - uint leftOverBits, - uint leftOverCount, - bool throwOnInvalid, bool flush) - { - // Validate the parameters. - if (bytes == null) { - throw new ArgumentNullException ("bytes"); - } - if (index < 0 || index > bytes.Length) { - throw new ArgumentOutOfRangeException ("index", _("ArgRange_Array")); - } - if (count < 0 || count > (bytes.Length - index)) { - throw new ArgumentOutOfRangeException ("count", _("ArgRange_Array")); - } - - // Determine the number of characters that we have. - int next_raw = 0; - uint ch; - int length = 0; - uint leftBits = leftOverBits; - uint leftSoFar = (leftOverCount & (uint)0x0F); - uint leftSize = ((leftOverCount >> 4) & (uint)0x0F); - while (count > 0) { - ch = (uint)(bytes[index++]); - ++next_raw; - --count; - if (leftSize == 0) { - // Process a UTF-8 start character. - if (ch < (uint)0x0080) { - // Single-byte UTF-8 character. - ++length; - next_raw = 0; - } else if ((ch & (uint)0xE0) == (uint)0xC0) { - // Double-byte UTF-8 character. - leftBits = (ch & (uint)0x1F); - leftSoFar = 1; - leftSize = 2; - } else if ((ch & (uint)0xF0) == (uint)0xE0) { - // Three-byte UTF-8 character. - leftBits = (ch & (uint)0x0F); - leftSoFar = 1; - leftSize = 3; - } else if ((ch & (uint)0xF8) == (uint)0xF0) { - // Four-byte UTF-8 character. - leftBits = (ch & (uint)0x07); - leftSoFar = 1; - leftSize = 4; - } else if ((ch & (uint)0xFC) == (uint)0xF8) { - // Five-byte UTF-8 character. - leftBits = (ch & (uint)0x03); - leftSoFar = 1; - leftSize = 5; - } else if ((ch & (uint)0xFE) == (uint)0xFC) { - // Six-byte UTF-8 character. - leftBits = (ch & (uint)0x03); - leftSoFar = 1; - leftSize = 6; - } else { - // Invalid UTF-8 start character. - if (throwOnInvalid) { - // throw new ArgumentException (_("Arg_InvalidUTF8"), "bytes"); - } - length += next_raw*2; - next_raw = 0; - } - } else { - // Process an extra byte in a multi-byte sequence. - if ((ch & (uint)0xC0) == (uint)0x80) { - leftBits = ((leftBits << 6) | (ch & (uint)0x3F)); - if (++leftSoFar >= leftSize) { - // We have a complete character now. - if (leftBits < (uint)0x10000) { - // is it an overlong ? - bool overlong = false; - switch (leftSize) { - case 2: - overlong = (leftBits <= 0x7F); - break; - case 3: - overlong = (leftBits <= 0x07FF); - break; - case 4: - overlong = (leftBits <= 0xFFFF); - break; - case 5: - overlong = (leftBits <= 0x1FFFFF); - break; - case 6: - overlong = (leftBits <= 0x03FFFFFF); - break; - } - if (overlong) { - // if (throwOnInvalid) - // throw new ArgumentException (_("Overlong"), leftBits.ToString ()); - length += next_raw*2; - } - else - ++length; - } else if (leftBits < (uint)0x110000) { - length += 2; - } else if (throwOnInvalid) { - // ??? - // throw new ArgumentException (_("Arg_InvalidUTF8"), "bytes"); - length += next_raw*2; - } - leftSize = 0; - next_raw = 0; - } - } else { - // Invalid UTF-8 sequence: clear and restart. - if (throwOnInvalid) { - // throw new ArgumentException (_("Arg_InvalidUTF8"), "bytes"); - } - // don't escape the current byte, process it normally - if (ch < (uint)0x0080) { - --index; - ++count; - --next_raw; - } - length += next_raw*2; - leftSize = 0; - next_raw = 0; - } - } - } - if (flush && leftSize != 0 && throwOnInvalid) { - // We had left-over bytes that didn't make up - // a complete UTF-8 character sequence. - // throw new ArgumentException (_("Arg_InvalidUTF8"), "bytes"); - length += next_raw * 2; - } - - // Return the final length to the caller. - return length; - } - - // Get the number of characters needed to decode a byte buffer. - public override int GetCharCount (byte[] bytes, int index, int count) - { - return InternalGetCharCount (bytes, index, count, 0, 0, true, true); - } - - // Get the characters that result from decoding a byte buffer. - private static int InternalGetChars (byte[] bytes, int byteIndex, - int byteCount, char[] chars, - int charIndex, ref uint leftOverBits, - ref uint leftOverCount, - bool throwOnInvalid, bool flush) - { - // Validate the parameters. - if (bytes == null) { - throw new ArgumentNullException ("bytes"); - } - if (chars == null) { - throw new ArgumentNullException ("chars"); - } - if (byteIndex < 0 || byteIndex > bytes.Length) { - throw new ArgumentOutOfRangeException ("byteIndex", _("ArgRange_Array")); - } - if (byteCount < 0 || byteCount > (bytes.Length - byteIndex)) { - throw new ArgumentOutOfRangeException ("byteCount", _("ArgRange_Array")); - } - if (charIndex < 0 || charIndex > chars.Length) { - throw new ArgumentOutOfRangeException ("charIndex", _("ArgRange_Array")); - } - - if (charIndex == chars.Length) - return 0; - - // Convert the bytes into the output buffer. - byte[] raw = new byte[6]; - int next_raw = 0; - uint ch; - int length = chars.Length; - int posn = charIndex; - uint leftBits = leftOverBits; - uint leftSoFar = (leftOverCount & (uint)0x0F); - uint leftSize = ((leftOverCount >> 4) & (uint)0x0F); - while (byteCount > 0) { - // Fetch the next character from the byte buffer. - ch = (uint)(bytes[byteIndex++]); - raw [next_raw++] = (byte) ch; - --byteCount; - if (leftSize == 0) { - // Process a UTF-8 start character. - if (ch < (uint)0x0080) { - // Single-byte UTF-8 character. - if (posn >= length) { - throw new ArgumentException (_("Arg_InsufficientSpace"), "chars"); - } - next_raw = 0; - chars[posn++] = (char)ch; - } else if ((ch & (uint)0xE0) == (uint)0xC0) { - // Double-byte UTF-8 character. - leftBits = (ch & (uint)0x1F); - leftSoFar = 1; - leftSize = 2; - } else if ((ch & (uint)0xF0) == (uint)0xE0) { - // Three-byte UTF-8 character. - leftBits = (ch & (uint)0x0F); - leftSoFar = 1; - leftSize = 3; - } else if ((ch & (uint)0xF8) == (uint)0xF0) { - // Four-byte UTF-8 character. - leftBits = (ch & (uint)0x07); - leftSoFar = 1; - leftSize = 4; - } else if ((ch & (uint)0xFC) == (uint)0xF8) { - // Five-byte UTF-8 character. - leftBits = (ch & (uint)0x03); - leftSoFar = 1; - leftSize = 5; - } else if ((ch & (uint)0xFE) == (uint)0xFC) { - // Six-byte UTF-8 character. - leftBits = (ch & (uint)0x03); - leftSoFar = 1; - leftSize = 6; - } else { - // Invalid UTF-8 start character. - if (throwOnInvalid) { - // throw new ArgumentException (_("Arg_InvalidUTF8"), "bytes"); - } - next_raw = 0; - chars[posn++] = EscapeByte; - chars[posn++] = (char) ch; - } - } else { - // Process an extra byte in a multi-byte sequence. - if ((ch & (uint)0xC0) == (uint)0x80) { - leftBits = ((leftBits << 6) | (ch & (uint)0x3F)); - if (++leftSoFar >= leftSize) { - // We have a complete character now. - if (leftBits < (uint)0x10000) { - // is it an overlong ? - bool overlong = false; - switch (leftSize) { - case 2: - overlong = (leftBits <= 0x7F); - break; - case 3: - overlong = (leftBits <= 0x07FF); - break; - case 4: - overlong = (leftBits <= 0xFFFF); - break; - case 5: - overlong = (leftBits <= 0x1FFFFF); - break; - case 6: - overlong = (leftBits <= 0x03FFFFFF); - break; - } - if (overlong) { - // if (throwOnInvalid) - // throw new ArgumentException (_("Overlong"), leftBits.ToString ()); - CopyRaw (raw, ref next_raw, chars, ref posn, length); - } - else { - if (posn >= length) { - throw new ArgumentException - (_("Arg_InsufficientSpace"), "chars"); - } - chars[posn++] = (char)leftBits; - } - } else if (leftBits < (uint)0x110000) { - if ((posn + 2) > length) { - throw new ArgumentException - (_("Arg_InsufficientSpace"), "chars"); - } - leftBits -= (uint)0x10000; - chars[posn++] = (char)((leftBits >> 10) + - (uint)0xD800); - chars[posn++] = - (char)((leftBits & (uint)0x3FF) + (uint)0xDC00); - } else if (throwOnInvalid) { - // ??? - // throw new ArgumentException (_("Arg_InvalidUTF8"), "bytes"); - CopyRaw (raw, ref next_raw, chars, ref posn, length); - } - leftSize = 0; - next_raw = 0; - } - } else { - // Invalid UTF-8 sequence: clear and restart. - if (throwOnInvalid) { - // throw new ArgumentException (_("Arg_InvalidUTF8"), "bytes"); - } - // don't escape the current byte, process it normally - if (ch < (uint)0x0080) { - --byteIndex; - ++byteCount; - --next_raw; - } - CopyRaw (raw, ref next_raw, chars, ref posn, length); - leftSize = 0; - next_raw = 0; - } - } - } - if (flush && leftSize != 0 && throwOnInvalid) { - // We had left-over bytes that didn't make up - // a complete UTF-8 character sequence. - // throw new ArgumentException (_("Arg_InvalidUTF8"), "bytes"); - CopyRaw (raw, ref next_raw, chars, ref posn, length); - } - leftOverBits = leftBits; - leftOverCount = (leftSoFar | (leftSize << 4)); - - // Return the final length to the caller. - return posn - charIndex; - } - - private static void CopyRaw (byte[] raw, ref int next_raw, char[] chars, ref int posn, int length) - { - if (posn+(next_raw*2) > length) - throw new ArgumentException (_("Arg_InsufficientSpace"), "chars"); - - for (int i = 0; i < next_raw; ++i) { - chars[posn++] = EscapeByte; - chars[posn++] = (char) raw [i]; - } - - next_raw = 0; - } - - // Get the characters that result from decoding a byte buffer. - public override int GetChars (byte[] bytes, int byteIndex, int byteCount, - char[] chars, int charIndex) - { - uint leftOverBits = 0; - uint leftOverCount = 0; - return InternalGetChars (bytes, byteIndex, byteCount, chars, - charIndex, ref leftOverBits, ref leftOverCount, true, true); - } - - // Get the maximum number of bytes needed to encode a - // specified number of characters. - public override int GetMaxByteCount (int charCount) - { - if (charCount < 0) { - throw new ArgumentOutOfRangeException ("charCount", _("ArgRange_NonNegative")); - } - return charCount * 4; - } - - // Get the maximum number of characters needed to decode a - // specified number of bytes. - public override int GetMaxCharCount (int byteCount) - { - if (byteCount < 0) { - throw new ArgumentOutOfRangeException ("byteCount", _("ArgRange_NonNegative")); - } - return byteCount; - } - - // Get a Unix-specific decoder that is attached to this instance. - public override Decoder GetDecoder () - { - return new UnixDecoder (); - } - - // Get a Unix-specific encoder that is attached to this instance. - public override Encoder GetEncoder () - { - return new UnixEncoder (); - } - - // Get the Unix preamble. - public override byte[] GetPreamble () - { - return new byte [0]; - } - - // Determine if this object is equal to another. - public override bool Equals (Object value) - { - UnixEncoding enc = (value as UnixEncoding); - if (enc != null) { - return true; - } - else { - return false; - } - } - - // Get the hash code for this object. - public override int GetHashCode () - { - return base.GetHashCode (); - } - - public override byte [] GetBytes (String s) - { - if (s == null) - throw new ArgumentNullException ("s"); - - int length = GetByteCount (s); - byte [] bytes = new byte [length]; - GetBytes (s, 0, s.Length, bytes, 0); - return bytes; - } - - // Unix decoder implementation. - [Serializable] - private class UnixDecoder : Decoder - { - private uint leftOverBits; - private uint leftOverCount; - - // Constructor. - public UnixDecoder () - { - leftOverBits = 0; - leftOverCount = 0; - } - - // Override inherited methods. - public override int GetCharCount (byte[] bytes, int index, int count) - { - return InternalGetCharCount (bytes, index, count, - leftOverBits, leftOverCount, true, false); - } - public override int GetChars (byte[] bytes, int byteIndex, - int byteCount, char[] chars, int charIndex) - { - return InternalGetChars (bytes, byteIndex, byteCount, - chars, charIndex, ref leftOverBits, ref leftOverCount, true, false); - } - - } - - // Unix encoder implementation. - [Serializable] - private class UnixEncoder : Encoder - { - private uint leftOver; - - // Constructor. - public UnixEncoder () - { - leftOver = 0; - } - - // Override inherited methods. - public override int GetByteCount (char[] chars, int index, - int count, bool flush) - { - return InternalGetByteCount (chars, index, count, leftOver, flush); - } - public override int GetBytes (char[] chars, int charIndex, - int charCount, byte[] bytes, int byteCount, bool flush) - { - int result; - result = InternalGetBytes (chars, charIndex, charCount, bytes, byteCount, ref leftOver, flush); - return result; - } - } - - private static string _ (string arg) - { - return arg; - } -} -} - diff --git a/LibZipSharp/Mono.Posix/Mono.Unix/UnixIOException.cs b/LibZipSharp/Mono.Posix/Mono.Unix/UnixIOException.cs deleted file mode 100644 index 4ded4ac..0000000 --- a/LibZipSharp/Mono.Posix/Mono.Unix/UnixIOException.cs +++ /dev/null @@ -1,104 +0,0 @@ -// -// Mono.Unix/UnixIOException.cs -// -// Authors: -// Jonathan Pryor (jonpryor@vt.edu) -// -// (C) 2004-2005 Jonathan Pryor -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.IO; -using System.Runtime.InteropServices; -using System.Runtime.Serialization; -using Mono.Unix; - -namespace Mono.Unix { - - [Serializable] - class UnixIOException : IOException - { - private int errno; - - public UnixIOException () - : this (Marshal.GetLastWin32Error()) - {} - - public UnixIOException (int errno) - : base (GetMessage (Native.NativeConvert.ToErrno (errno))) - { - this.errno = errno; - } - - public UnixIOException (int errno, Exception inner) - : base (GetMessage (Native.NativeConvert.ToErrno (errno)), inner) - { - this.errno = errno; - } - - public UnixIOException (Native.Errno errno) - : base (GetMessage (errno)) - { - this.errno = Native.NativeConvert.FromErrno (errno); - } - - public UnixIOException (Native.Errno errno, Exception inner) - : base (GetMessage (errno), inner) - { - this.errno = Native.NativeConvert.FromErrno (errno); - } - - public UnixIOException (string message) - : base (message) - { - this.errno = 0; - } - - public UnixIOException (string message, Exception inner) - : base (message, inner) - { - this.errno = 0; - } - - protected UnixIOException (SerializationInfo info, StreamingContext context) - : base (info, context) - { - } - - public int NativeErrorCode { - get {return errno;} - } - - public Native.Errno ErrorCode { - get {return Native.NativeConvert.ToErrno (errno);} - } - - private static string GetMessage (Native.Errno errno) - { - return string.Format ("{0} [{1}].", - UnixMarshal.GetErrorDescription (errno), - errno); - } - } -} - -// vim: noexpandtab diff --git a/LibZipSharp/Mono.Posix/Mono.Unix/UnixMarshal.cs b/LibZipSharp/Mono.Posix/Mono.Unix/UnixMarshal.cs deleted file mode 100644 index abb4c7d..0000000 --- a/LibZipSharp/Mono.Posix/Mono.Unix/UnixMarshal.cs +++ /dev/null @@ -1,478 +0,0 @@ -// -// Mono.Unix/UnixMarshal.cs -// -// Authors: -// Jonathan Pryor (jonpryor@vt.edu) -// -// (C) 2004-2006 Jonathan Pryor -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.IO; -using System.Net.Sockets; -using System.Runtime.InteropServices; -using System.Runtime.Serialization; -using System.Text; -using Mono.Unix; - -namespace Mono.Unix { - - // Scenario: We want to be able to translate an Error to a string. - // Problem: Thread-safety. Strerror(3) isn't thread safe (unless - // thread-local-variables are used, which is probably only - // true on Windows). - // Solution: Use strerror_r(). - // Problem: strerror_r() isn't portable. - // (Apparently Solaris doesn't provide it.) - // Solution: Cry. Then introduce an intermediary, ErrorMarshal. - // ErrorMarshal exposes a single public delegate, Translator, - // which will convert an Error to a string. It's static - // constructor first tries using strerror_r(). If it works, - // great; use it in the future. If it doesn't work, fallback to - // using strerror(3). - // This should be thread safe, since the check is done within the - // class constructor lock. - // Strerror(3) will be thread-safe from managed code, but won't - // be thread-safe between managed & unmanaged code. - internal class ErrorMarshal - { - internal delegate string ErrorTranslator (Native.Errno errno); - - internal static readonly ErrorTranslator Translate; - - static ErrorMarshal () - { - try { - Translate = new ErrorTranslator (strerror_r); - Translate (Native.Errno.ERANGE); - } - catch (EntryPointNotFoundException) { - Translate = new ErrorTranslator (strerror); - } - } - - private static string strerror (Native.Errno errno) - { - return Native.Stdlib.strerror (errno); - } - - private static string strerror_r (Native.Errno errno) - { - StringBuilder buf = new StringBuilder (16); - int r = 0; - do { - buf.Capacity *= 2; - r = Native.Syscall.strerror_r (errno, buf); - } while (r == -1 && Native.Stdlib.GetLastError() == Native.Errno.ERANGE); - - if (r == -1) - return "** Unknown error code: " + ((int) errno) + "**"; - return buf.ToString(); - } - } - - sealed /* static */ class UnixMarshal - { - private UnixMarshal () {} - - [CLSCompliant (false)] - public static string GetErrorDescription (Native.Errno errno) - { - return ErrorMarshal.Translate (errno); - } - - public static IntPtr AllocHeap (long size) - { - if (size < 0) - throw new ArgumentOutOfRangeException ("size", "< 0"); - return Native.Stdlib.malloc ((ulong) size); - } - - public static IntPtr ReAllocHeap (IntPtr ptr, long size) - { - if (size < 0) - throw new ArgumentOutOfRangeException ("size", "< 0"); - return Native.Stdlib.realloc (ptr, (ulong) size); - } - - public static void FreeHeap (IntPtr ptr) - { - Native.Stdlib.free (ptr); - } - - public static unsafe string PtrToStringUnix (IntPtr p) - { - if (p == IntPtr.Zero) - return null; - - int len = checked ((int) Native.Stdlib.strlen (p)); - return new string ((sbyte*) p, 0, len, UnixEncoding.Instance); - } - - public static string PtrToString (IntPtr p) - { - if (p == IntPtr.Zero) - return null; - return PtrToString (p, UnixEncoding.Instance); - } - - public static unsafe string PtrToString (IntPtr p, Encoding encoding) - { - if (p == IntPtr.Zero) - return null; - - if (encoding == null) - throw new ArgumentNullException ("encoding"); - - int len = GetStringByteLength (p, encoding); - - // Due to variable-length encoding schemes, GetStringByteLength() may - // have returned multiple "null" characters. (For example, when - // encoding a string into UTF-8 there will be 4 terminating nulls.) - // We don't want these null's to be in the returned string, so strip - // them off. - string s = new string ((sbyte*) p, 0, len, encoding); - len = s.Length; - while (len > 0 && s [len-1] == 0) - --len; - if (len == s.Length) - return s; - return s.Substring (0, len); - } - - private static int GetStringByteLength (IntPtr p, Encoding encoding) - { - Type encodingType = encoding.GetType (); - - int len = -1; - - // Encodings that will always end with a single null byte - if (typeof(UTF8Encoding).IsAssignableFrom (encodingType) || - typeof(UTF7Encoding).IsAssignableFrom (encodingType) || - typeof(UnixEncoding).IsAssignableFrom (encodingType) || - typeof(ASCIIEncoding).IsAssignableFrom (encodingType)) { - len = checked ((int) Native.Stdlib.strlen (p)); - } - // Encodings that will always end with a 0x0000 16-bit word - else if (typeof(UnicodeEncoding).IsAssignableFrom (encodingType)) { - len = GetInt16BufferLength (p); - } - // Encodings that will always end with a 0x00000000 32-bit word - else if (typeof(UTF32Encoding).IsAssignableFrom (encodingType)) { - len = GetInt32BufferLength (p); - } - // Some non-public encoding, such as Latin1 or a DBCS charset. - // Look for a sequence of encoding.GetMaxByteCount() bytes that are all - // 0, which should be the terminating null. - // This is "iffy", since it may fail for variable-width encodings; for - // example, UTF8Encoding.GetMaxByteCount(1) = 4, so this would read 3 - // bytes past the end of the string, possibly into garbage memory - // (which is why we special case UTF above). - else { - len = GetRandomBufferLength (p, encoding.GetMaxByteCount(1)); - } - - if (len == -1) - throw new NotSupportedException ("Unable to determine native string buffer length"); - return len; - } - - private static int GetInt16BufferLength (IntPtr p) - { - int len = 0; - while (Marshal.ReadInt16 (p, len*2) != 0) - checked {++len;} - return checked(len*2); - } - - private static int GetInt32BufferLength (IntPtr p) - { - int len = 0; - while (Marshal.ReadInt32 (p, len*4) != 0) - checked {++len;} - return checked(len*4); - } - - private static int GetRandomBufferLength (IntPtr p, int nullLength) - { - switch (nullLength) { - case 1: return checked ((int) Native.Stdlib.strlen (p)); - case 2: return GetInt16BufferLength (p); - case 4: return GetInt32BufferLength (p); - } - - int len = 0; - int num_null_seen = 0; - - do { - byte b = Marshal.ReadByte (p, len++); - if (b == 0) - ++num_null_seen; - else - num_null_seen = 0; - } while (num_null_seen != nullLength); - - return len; - } - - /* - * Marshal a C `char **'. ANSI C `main' requirements are assumed: - * - * stringArray is an array of pointers to C strings - * stringArray has a terminating NULL string. - * - * For example: - * stringArray[0] = "string 1"; - * stringArray[1] = "string 2"; - * stringArray[2] = NULL - * - * The terminating NULL is required so that we know when to stop looking - * for strings. - */ - public static string[] PtrToStringArray (IntPtr stringArray) - { - return PtrToStringArray (stringArray, UnixEncoding.Instance); - } - - public static string[] PtrToStringArray (IntPtr stringArray, Encoding encoding) - { - if (stringArray == IntPtr.Zero) - return new string[]{}; - - int argc = CountStrings (stringArray); - return PtrToStringArray (argc, stringArray, encoding); - } - - private static int CountStrings (IntPtr stringArray) - { - int count = 0; - while (Marshal.ReadIntPtr (stringArray, count*IntPtr.Size) != IntPtr.Zero) - ++count; - return count; - } - - /* - * Like PtrToStringArray(IntPtr), but it allows the user to specify how - * many strings to look for in the array. As such, the requirement for a - * terminating NULL element is not required. - * - * Usage is similar to ANSI C `main': count is argc, stringArray is argv. - * stringArray[count] is NOT accessed (though ANSI C requires that - * argv[argc] = NULL, which PtrToStringArray(IntPtr) requires). - */ - public static string[] PtrToStringArray (int count, IntPtr stringArray) - { - return PtrToStringArray (count, stringArray, UnixEncoding.Instance); - } - - public static string[] PtrToStringArray (int count, IntPtr stringArray, Encoding encoding) - { - if (count < 0) - throw new ArgumentOutOfRangeException ("count", "< 0"); - if (encoding == null) - throw new ArgumentNullException ("encoding"); - if (stringArray == IntPtr.Zero) - return new string[count]; - - string[] members = new string[count]; - for (int i = 0; i < count; ++i) { - IntPtr s = Marshal.ReadIntPtr (stringArray, i * IntPtr.Size); - members[i] = PtrToString (s, encoding); - } - - return members; - } - - public static IntPtr StringToHeap (string s) - { - return StringToHeap (s, UnixEncoding.Instance); - } - - public static IntPtr StringToHeap (string s, Encoding encoding) - { - return StringToHeap (s, 0, s.Length, encoding); - } - - public static IntPtr StringToHeap (string s, int index, int count) - { - return StringToHeap (s, index, count, UnixEncoding.Instance); - } - - public static IntPtr StringToHeap (string s, int index, int count, Encoding encoding) - { - if (s == null) - return IntPtr.Zero; - - if (encoding == null) - throw new ArgumentNullException ("encoding"); - - int min_byte_count = encoding.GetMaxByteCount(1); - char[] copy = s.ToCharArray (index, count); - byte[] marshal = new byte [encoding.GetByteCount (copy) + min_byte_count]; - - int bytes_copied = encoding.GetBytes (copy, 0, copy.Length, marshal, 0); - - if (bytes_copied != (marshal.Length-min_byte_count)) - throw new NotSupportedException ("encoding.GetBytes() doesn't equal encoding.GetByteCount()!"); - - IntPtr mem = AllocHeap (marshal.Length); - if (mem == IntPtr.Zero) - throw new UnixIOException (Native.Errno.ENOMEM); - - bool copied = false; - try { - Marshal.Copy (marshal, 0, mem, marshal.Length); - copied = true; - } - finally { - if (!copied) - FreeHeap (mem); - } - - return mem; - } - - public static bool ShouldRetrySyscall (int r) - { - if (r == -1 && Native.Stdlib.GetLastError () == Native.Errno.EINTR) - return true; - return false; - } - - [CLSCompliant (false)] - public static bool ShouldRetrySyscall (int r, out Native.Errno errno) - { - errno = (Native.Errno) 0; - if (r == -1 && (errno = Native.Stdlib.GetLastError ()) == Native.Errno.EINTR) - return true; - return false; - } - - // we can't permit any printf(3)-style formatting information, since that - // would kill the stack. However, replacing %% is silly, and some %* are - // permitted (such as %m in syslog to print strerror(errno)). - internal static string EscapeFormatString (string message, - char [] permitted) - { - if (message == null) - return ""; - StringBuilder sb = new StringBuilder (message.Length); - for (int i = 0; i < message.Length; ++i) { - char c = message [i]; - sb.Append (c); - if (c == '%' && (i+1) < message.Length) { - char n = message [i+1]; - if (n == '%' || IsCharPresent (permitted, n)) - sb.Append (n); - else - sb.Append ('%').Append (n); - ++i; - } - // invalid format string: % at EOS. - else if (c == '%') - sb.Append ('%'); - } - return sb.ToString (); - } - - private static bool IsCharPresent (char[] array, char c) - { - if (array == null) - return false; - for (int i = 0; i < array.Length; ++i) - if (array [i] == c) - return true; - return false; - } - - internal static Exception CreateExceptionForError (Native.Errno errno) - { - string message = GetErrorDescription (errno); - UnixIOException p = new UnixIOException (errno); - - // Ordering: Order alphabetically by exception first (right column), - // then order alphabetically by Errno value (left column) for the given - // exception. - switch (errno) { - case Native.Errno.EBADF: - case Native.Errno.EINVAL: return new ArgumentException (message, p); - - case Native.Errno.ERANGE: return new ArgumentOutOfRangeException (message); - case Native.Errno.ENOTDIR: return new DirectoryNotFoundException (message, p); - case Native.Errno.ENOENT: return new FileNotFoundException (message, p); - - case Native.Errno.EOPNOTSUPP: - case Native.Errno.EPERM: return new InvalidOperationException (message, p); - - case Native.Errno.ENOEXEC: return new InvalidProgramException (message, p); - - case Native.Errno.EIO: - case Native.Errno.ENOSPC: - case Native.Errno.ENOTEMPTY: - case Native.Errno.ENXIO: - case Native.Errno.EROFS: - case Native.Errno.ESPIPE: return new IOException (message, p); - - case Native.Errno.EFAULT: return new NullReferenceException (message, p); - case Native.Errno.EOVERFLOW: return new OverflowException (message, p); - case Native.Errno.ENAMETOOLONG: return new PathTooLongException (message, p); - - case Native.Errno.EACCES: - case Native.Errno.EISDIR: return new UnauthorizedAccessException (message, p); - - default: /* ignore */ break; - } - return p; - } - - internal static Exception CreateExceptionForLastError () - { - return CreateExceptionForError (Native.Stdlib.GetLastError()); - } - - [CLSCompliant (false)] - public static void ThrowExceptionForError (Native.Errno errno) - { - throw CreateExceptionForError (errno); - } - - public static void ThrowExceptionForLastError () - { - throw CreateExceptionForLastError (); - } - - [CLSCompliant (false)] - public static void ThrowExceptionForErrorIf (int retval, Native.Errno errno) - { - if (retval == -1) - ThrowExceptionForError (errno); - } - - public static void ThrowExceptionForLastErrorIf (int retval) - { - if (retval == -1) - ThrowExceptionForLastError (); - } - } -} - -// vim: noexpandtab diff --git a/LibZipSharp/libZipSharp.csproj b/LibZipSharp/libZipSharp.csproj index 2d2707b..27f3c03 100644 --- a/LibZipSharp/libZipSharp.csproj +++ b/LibZipSharp/libZipSharp.csproj @@ -57,7 +57,7 @@ - + diff --git a/ZipTest/ZipTest.csproj b/ZipTest/ZipTest.csproj index 6d22768..b03f6c2 100644 --- a/ZipTest/ZipTest.csproj +++ b/ZipTest/ZipTest.csproj @@ -16,7 +16,6 @@ - @@ -33,6 +32,7 @@ + {E248B2CA-303B-4645-ADDC-9D4459D550FD} libZipSharp diff --git a/build.sh b/build.sh index 92298f3..1a28520 100755 --- a/build.sh +++ b/build.sh @@ -85,6 +85,7 @@ where OPTIONS are one or more of: -h|--help show this message EOF + exit 0 } function print_banner()