]> wimlib.net Git - wimlib/blobdiff - src/util.c
unix_capture.c: Include <limits.h> for PATH_MAX
[wimlib] / src / util.c
index 485303eb834da3063befa35f3730aec6d0b7638b..a5899bcd349db00366206ce934ab20cb82260527 100644 (file)
 #include <errno.h>
 #include <stdarg.h>
 #include <stdlib.h>
-#include <sys/uio.h>
 #include <unistd.h>
 
 
 #ifdef __WIN32__
-#include "win32.h"
+#  include "win32.h"
+#  define pread         win32_pread
+#  define pwrite win32_pwrite
+#  define writev win32_writev
+#else
+#  include <sys/uio.h> /* for writev() and `struct iovec' */
 #endif
 
 static size_t
@@ -318,6 +322,8 @@ static const tchar *error_strings[] = {
                = T("A string provided as input by the user was not a valid UTF-8 string"),
        [WIMLIB_ERR_INVALID_UTF16_STRING]
                = T("A string in a WIM dentry is not a valid UTF-16LE string"),
+       [WIMLIB_ERR_IS_DIRECTORY]
+               = T("One of the specified paths to delete was a directory"),
        [WIMLIB_ERR_LIBXML_UTF16_HANDLER_NOT_AVAILABLE]
                = T("libxml2 was unable to find a character encoding conversion handler "
                  "for UTF-16LE"),
@@ -332,9 +338,14 @@ static const tchar *error_strings[] = {
                = T("Ran out of memory"),
        [WIMLIB_ERR_NOTDIR]
                = T("Expected a directory"),
+       [WIMLIB_ERR_NOTEMPTY]
+               = T("Directory was not empty"),
        [WIMLIB_ERR_NOT_A_WIM_FILE]
                = T("The file did not begin with the magic characters that "
                        "identify a WIM file"),
+       [WIMLIB_ERR_NOT_A_REGULAR_FILE]
+               = T("One of the specified paths to extract did not "
+                   "correspond to a regular file"),
        [WIMLIB_ERR_NO_FILENAME]
                = T("The WIM is not identified with a filename"),
        [WIMLIB_ERR_NTFS_3G]
@@ -343,6 +354,8 @@ static const tchar *error_strings[] = {
                = T("Failed to open a file"),
        [WIMLIB_ERR_OPENDIR]
                = T("Failed to open a directory"),
+       [WIMLIB_ERR_PATH_DOES_NOT_EXIST]
+               = T("The path does not exist in the WIM image"),
        [WIMLIB_ERR_READ]
                = T("Could not read data from a file"),
        [WIMLIB_ERR_READLINK]
@@ -566,6 +579,45 @@ zap_backslashes(tchar *s)
        }
 }
 
+tchar *
+canonicalize_fs_path(const tchar *fs_path)
+{
+       tchar *canonical_path;
+
+       if (!fs_path)
+               fs_path = T("");
+       canonical_path = TSTRDUP(fs_path);
+       zap_backslashes(canonical_path);
+       return canonical_path;
+}
+
+/* Strip leading and trailing slashes from a string.  Also translates
+ * backslashes into forward slashes.  */
+tchar *
+canonicalize_wim_path(const tchar *wim_path)
+{
+       tchar *p;
+       tchar *canonical_path;
+
+       if (wim_path == NULL) {
+               wim_path = T("");
+       } else {
+               while (*wim_path == T('/') || *wim_path == T('\\'))
+                       wim_path++;
+       }
+       canonical_path = TSTRDUP(wim_path);
+       if (canonical_path) {
+               zap_backslashes(canonical_path);
+               for (p = tstrchr(canonical_path, T('\0')) - 1;
+                    p >= canonical_path && *p == T('/');
+                    p--)
+               {
+                       *p = T('\0');
+               }
+       }
+       return canonical_path;
+}
+
 /* Like read(), but keep trying until everything has been written or we know for
  * sure that there was an error (or end-of-file). */
 size_t
@@ -692,7 +744,7 @@ full_writev(int fd, struct iovec *iov, int iovcnt)
 }
 
 off_t
-filedes_offset(filedes_t fd)
+filedes_offset(int fd)
 {
        return lseek(fd, 0, SEEK_CUR);
 }