]> wimlib.net Git - wimlib/commitdiff
filedes_t => int
authorEric Biggers <ebiggers3@gmail.com>
Sun, 5 May 2013 03:38:39 +0000 (22:38 -0500)
committerEric Biggers <ebiggers3@gmail.com>
Sun, 5 May 2013 03:38:39 +0000 (22:38 -0500)
15 files changed:
src/header.c
src/integrity.c
src/join.c
src/lookup_table.c
src/lookup_table.h
src/metadata_resource.c
src/resource.c
src/split.c
src/util.c
src/util.h
src/wim.c
src/wimlib_internal.h
src/write.c
src/xml.c
src/xml.h

index 2524793d5c66b89de94d45a298cde5c4647a0787..70abf2f27dee701dcdb97c71556f135b9607df66 100644 (file)
@@ -33,7 +33,7 @@ static const u8 wim_magic_chars[WIM_MAGIC_LEN] = {
 
 /* Reads the header from a WIM file.  */
 int
-read_header(filedes_t in_fd, struct wim_header *hdr, int open_flags)
+read_header(int in_fd, struct wim_header *hdr, int open_flags)
 {
        size_t bytes_read;
        u8 buf[WIM_HEADER_DISK_SIZE];
index 37ff7b7484fe1f7692a135304773aa00571ef977..9afec969a0fc7efa5afa5191e40ab9c804cc7e63 100644 (file)
@@ -46,7 +46,7 @@ struct integrity_table {
 };
 
 static int
-calculate_chunk_sha1(filedes_t in_fd, size_t this_chunk_size,
+calculate_chunk_sha1(int in_fd, size_t this_chunk_size,
                     off_t offset, u8 sha1_md[])
 {
        u8 buf[BUFFER_SIZE];
@@ -100,7 +100,7 @@ calculate_chunk_sha1(filedes_t in_fd, size_t this_chunk_size,
  */
 static int
 read_integrity_table(const struct resource_entry *res_entry,
-                    filedes_t in_fd,
+                    int in_fd,
                     u64 num_checked_bytes,
                     struct integrity_table **table_ret)
 {
@@ -223,7 +223,7 @@ out:
  * Returns 0 on success; nonzero on failure.
  */
 static int
-calculate_integrity_table(filedes_t in_fd,
+calculate_integrity_table(int in_fd,
                          off_t new_check_end,
                          const struct integrity_table *old_table,
                          off_t old_check_end,
@@ -354,7 +354,7 @@ calculate_integrity_table(filedes_t in_fd,
  *                             to be checked.
  */
 int
-write_integrity_table(filedes_t fd,
+write_integrity_table(int fd,
                      struct resource_entry *integrity_res_entry,
                      off_t new_lookup_table_end,
                      off_t old_lookup_table_end,
@@ -441,7 +441,7 @@ out_free_old_table:
  *     -1 (WIM_INTEGRITY_NOT_OK) if the WIM failed the integrity check.
  */
 static int
-verify_integrity(filedes_t in_fd, const tchar *filename,
+verify_integrity(int in_fd, const tchar *filename,
                 const struct integrity_table *table,
                 u64 bytes_to_check,
                 wimlib_progress_func_t progress_func)
index 1de8b76bb1b24e666f608fa912852f6ffd625e9e..b6bf6ebd78d22d598d3e6e536cab2dbe706f7386 100644 (file)
@@ -127,7 +127,7 @@ join_wims(WIMStruct **swms, unsigned num_swms,
                ret = for_lookup_table_entry_pos_sorted(swms[i]->lookup_table,
                                                        copy_resource,
                                                        swms[i]);
-               swms[i]->out_fd = INVALID_FILEDES;
+               swms[i]->out_fd = -1;
                if (i != 0)
                        close_wim(swms[i]);
 
index c3bd2acbb7cb7fd56e4767228add616bd5797e06..e2ca5920745f84b733bdfb794928c4f5a516e821 100644 (file)
@@ -534,7 +534,7 @@ write_lookup_table_entry(struct wim_lookup_table_entry *lte, u8 *buf_p)
 
 int
 write_lookup_table_from_stream_list(struct list_head *stream_list,
-                                   filedes_t out_fd,
+                                   int out_fd,
                                    struct resource_entry *out_res_entry)
 {
        int ret;
index 38b52ea8fbd79dbec9a4fb7593529bddfe0cb8b9..921a47c3e627fdb968ee9d6a7e48a66d4afbb04c 100644 (file)
@@ -309,7 +309,7 @@ write_lookup_table(WIMStruct *w, int image, struct resource_entry *out_res_entry
 
 extern int
 write_lookup_table_from_stream_list(struct list_head *stream_list,
-                                   filedes_t out_fd,
+                                   int out_fd,
                                    struct resource_entry *out_res_entry);
 
 extern void
index b55609e667d74e598dc867f576a5a649cc7a0dc8..3e8b7283e17f3267fb5d660df3db0412e41c9150 100644 (file)
@@ -194,7 +194,7 @@ recalculate_security_data_length(struct wim_security_data *sd)
  * the buffer to @hash.  */
 static int
 write_wim_resource_from_buffer(const void *buf, size_t buf_size,
-                              filedes_t out_fd, int out_ctype,
+                              int out_fd, int out_ctype,
                               struct resource_entry *out_res_entry,
                               u8 hash[SHA1_HASH_SIZE])
 {
@@ -226,7 +226,7 @@ write_metadata_resource(WIMStruct *w)
        u64 metadata_original_size;
        struct wim_security_data *sd;
 
-       wimlib_assert(w->out_fd != INVALID_FILEDES);
+       wimlib_assert(w->out_fd != -1);
        wimlib_assert(w->current_image != WIMLIB_NO_IMAGE);
 
        DEBUG("Writing metadata resource for image %d (offset = %"PRIu64")",
index 8e1fd2415693d6d2da8cb9351fbc8215359f4320..f54ea259bb5e91c79fd52e8b2cd37f9874b12897 100644 (file)
@@ -48,7 +48,7 @@
  * Returns zero on success, nonzero on failure.
  */
 static int
-read_compressed_resource(filedes_t in_fd,
+read_compressed_resource(int in_fd,
                         u64 resource_compressed_size,
                         u64 resource_uncompressed_size,
                         u64 resource_offset,
@@ -397,7 +397,7 @@ read_partial_wim_resource(const struct wim_lookup_table_entry *lte,
                          u64 offset)
 {
        WIMStruct *wim;
-       filedes_t in_fd;
+       int in_fd;
        int ret;
 
        wimlib_assert(lte->resource_location == RESOURCE_IN_WIM);
index 8b67079e0f507316eba1b91f40ab0aefac143a1a..5b14b924771451fd7c683ff4176209a60857750a 100644 (file)
@@ -226,7 +226,7 @@ wimlib_split(WIMStruct *w, const tchar *swm_name,
                }
 
                part_fd = topen(part_name, O_WRONLY | O_BINARY);
-               if (part_fd == INVALID_FILEDES) {
+               if (part_fd == -1) {
                        ERROR_WITH_ERRNO("Failed to open `%"TS"'", part_name);
                        ret = WIMLIB_ERR_OPEN;
                        goto out;
index 709ba46537d766894607a61cfbaadf5e95e44119..5421a6b5c53beab448e4c23a9d9be1004b92f8ea 100644 (file)
@@ -696,7 +696,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);
 }
index 935bbba6c2652939fb14dc7d73f56a2e981be4a2..660dcf996071c51a8a5b823df5044e109c23d37c 100644 (file)
@@ -285,19 +285,17 @@ hash_u64(u64 n)
        return n * 0x9e37fffffffc0001ULL;
 }
 
-typedef int filedes_t;
-
 extern size_t
-full_read(filedes_t fd, void *buf, size_t n);
+full_read(int fd, void *buf, size_t n);
 
 extern size_t
-full_write(filedes_t fd, const void *buf, size_t n);
+full_write(int fd, const void *buf, size_t n);
 
 extern size_t
-full_pread(filedes_t fd, void *buf, size_t nbyte, off_t offset);
+full_pread(int fd, void *buf, size_t nbyte, off_t offset);
 
 extern size_t
-full_pwrite(filedes_t fd, const void *buf, size_t count, off_t offset);
+full_pwrite(int fd, const void *buf, size_t count, off_t offset);
 
 #ifdef __WIN32__
 struct iovec {
@@ -308,17 +306,14 @@ struct iovec {
 struct iovec;
 #endif
 
-
 extern size_t
 full_writev(int fd, struct iovec *iov, int iovcnt);
 
 extern off_t
-filedes_offset(filedes_t fd);
+filedes_offset(int fd);
 
 #ifndef __WIN32__
 #  define O_BINARY 0
 #endif
 
-#define INVALID_FILEDES (-1)
-
 #endif /* _WIMLIB_UTIL_H */
index 07c1a376d49548a44b6411fb40609b1db2613f5d..c320b311ea21f32be9c2e06c0e65ed696a029c5a 100644 (file)
--- a/src/wim.c
+++ b/src/wim.c
@@ -66,8 +66,8 @@ new_wim_struct()
 {
        WIMStruct *w = CALLOC(1, sizeof(WIMStruct));
        if (w) {
-               w->in_fd = INVALID_FILEDES;
-               w->out_fd = INVALID_FILEDES;
+               w->in_fd = -1;
+               w->out_fd = -1;
        }
        return w;
 }
@@ -385,12 +385,12 @@ wimlib_get_boot_idx(const WIMStruct *w)
 }
 
 static int
-do_open_wim(const tchar *filename, filedes_t *fd_ret)
+do_open_wim(const tchar *filename, int *fd_ret)
 {
        int fd;
 
        fd = topen(filename, O_RDONLY | O_BINARY);
-       if (fd == INVALID_FILEDES) {
+       if (fd == -1) {
                ERROR_WITH_ERRNO("Can't open \"%"TS"\" read-only", filename);
                return WIMLIB_ERR_OPEN;
        }
@@ -401,16 +401,16 @@ do_open_wim(const tchar *filename, filedes_t *fd_ret)
 int
 reopen_wim(WIMStruct *w)
 {
-       wimlib_assert(w->in_fd == INVALID_FILEDES);
+       wimlib_assert(w->in_fd == -1);
        return do_open_wim(w->filename, &w->in_fd);
 }
 
 int
 close_wim(WIMStruct *w)
 {
-       if (w->in_fd != INVALID_FILEDES) {
+       if (w->in_fd != -1) {
                close(w->in_fd);
-               w->in_fd = INVALID_FILEDES;
+               w->in_fd = -1;
        }
        return 0;
 }
@@ -671,9 +671,9 @@ wimlib_free(WIMStruct *w)
 
        if (!w)
                return;
-       if (w->in_fd != INVALID_FILEDES)
+       if (w->in_fd != -1)
                close(w->in_fd);
-       if (w->out_fd != INVALID_FILEDES)
+       if (w->out_fd != -1)
                close(w->out_fd);
 
        free_lookup_table(w->lookup_table);
index 65dd8a1d7f4acf41c1956d962a732e92dc2203bb..f668dfd69a3cfa5184eb4e320f6aed09281390d6 100644 (file)
@@ -282,12 +282,12 @@ struct WIMStruct {
 
        /* File descriptor for the WIM file, opened for reading, or -1 if it has
         * not been opened or there is no associated file backing it yet. */
-       filedes_t in_fd;
+       int in_fd;
 
        /* File descriptor, opened either for writing only or for
         * reading+writing, for the WIM file (if any) currently being written.
         * */
-       filedes_t out_fd;
+       int out_fd;
 
        /* The name of the WIM file (if any) that has been opened. */
        tchar *filename;
@@ -493,10 +493,10 @@ dentry_tree_fix_inodes(struct wim_dentry *root, struct list_head *inode_list);
 /* header.c */
 
 extern int
-read_header(filedes_t in_fd, struct wim_header *hdr, int split_ok);
+read_header(int in_fd, struct wim_header *hdr, int split_ok);
 
 extern int
-write_header(const struct wim_header *hdr, filedes_t out_fd);
+write_header(const struct wim_header *hdr, int out_fd);
 
 extern int
 init_header(struct wim_header *hdr, int ctype);
@@ -508,7 +508,7 @@ init_header(struct wim_header *hdr, int ctype);
 #define WIM_INTEGRITY_NONEXISTENT -2
 
 extern int
-write_integrity_table(filedes_t fd,
+write_integrity_table(int fd,
                      struct resource_entry *integrity_res_entry,
                      off_t new_lookup_table_end,
                      off_t old_lookup_table_end,
@@ -689,7 +689,7 @@ extern int
 read_full_resource_into_buf(const struct wim_lookup_table_entry *lte, void *buf);
 
 extern int
-write_wim_resource(struct wim_lookup_table_entry *lte, filedes_t out_fd,
+write_wim_resource(struct wim_lookup_table_entry *lte, int out_fd,
                   int out_ctype, struct resource_entry *out_res_entry,
                   int flags);
 
@@ -796,10 +796,10 @@ finish_write(WIMStruct *w, int image, int write_flags,
 
 #if defined(HAVE_SYS_FILE_H) && defined(HAVE_FLOCK)
 extern int
-lock_wim(WIMStruct *w, filedes_t fd);
+lock_wim(WIMStruct *w, int fd);
 #else
 static inline int
-lock_wim(WIMStruct *w, filedes_t fd)
+lock_wim(WIMStruct *w, int fd)
 {
        return 0;
 }
index b5954e342d81bdd7b2370e261da58f982b92fc45..d184a64a23485689dc27ad3704b3c4b79da6875d 100644 (file)
@@ -178,7 +178,7 @@ get_compress_func(int out_ctype)
 static int
 write_wim_resource_chunk(const void * restrict chunk,
                         unsigned chunk_size,
-                        filedes_t out_fd,
+                        int out_fd,
                         compress_func_t compress,
                         struct chunk_table * restrict chunk_tab)
 {
@@ -219,7 +219,7 @@ write_wim_resource_chunk(const void * restrict chunk,
  */
 static int
 finish_wim_resource_chunk_tab(struct chunk_table *chunk_tab,
-                             filedes_t out_fd, u64 *compressed_size_p)
+                             int out_fd, u64 *compressed_size_p)
 {
        size_t bytes_written;
 
@@ -244,7 +244,7 @@ finish_wim_resource_chunk_tab(struct chunk_table *chunk_tab,
 }
 
 static int
-seek_and_truncate(filedes_t out_fd, off_t offset)
+seek_and_truncate(int out_fd, off_t offset)
 {
        if (lseek(out_fd, offset, SEEK_SET) == -1 ||
            ftruncate(out_fd, offset))
@@ -280,7 +280,7 @@ finalize_and_check_sha1(SHA_CTX * restrict sha_ctx,
 struct write_resource_ctx {
        compress_func_t compress;
        struct chunk_table *chunk_tab;
-       filedes_t out_fd;
+       int out_fd;
        SHA_CTX sha_ctx;
        bool doing_sha;
 };
@@ -324,7 +324,7 @@ write_resource_cb(const void *restrict chunk, size_t chunk_size,
  */
 int
 write_wim_resource(struct wim_lookup_table_entry *lte,
-                  filedes_t out_fd, int out_ctype,
+                  int out_fd, int out_ctype,
                   struct resource_entry *out_res_entry,
                   int flags)
 {
@@ -620,7 +620,7 @@ do_write_streams_progress(union wimlib_progress_info *progress,
 }
 
 struct serial_write_stream_ctx {
-       filedes_t out_fd;
+       int out_fd;
        int out_ctype;
        int write_resource_flags;
 };
@@ -715,7 +715,7 @@ do_write_stream_list(struct list_head *stream_list,
 static int
 do_write_stream_list_serial(struct list_head *stream_list,
                            struct wim_lookup_table *lookup_table,
-                           filedes_t out_fd,
+                           int out_fd,
                            int out_ctype,
                            int write_resource_flags,
                            wimlib_progress_func_t progress_func,
@@ -747,7 +747,7 @@ write_flags_to_resource_flags(int write_flags)
 static int
 write_stream_list_serial(struct list_head *stream_list,
                         struct wim_lookup_table *lookup_table,
-                        filedes_t out_fd,
+                        int out_fd,
                         int out_ctype,
                         int write_resource_flags,
                         wimlib_progress_func_t progress_func,
@@ -768,7 +768,7 @@ write_stream_list_serial(struct list_head *stream_list,
 
 #ifdef ENABLE_MULTITHREADED_COMPRESSION
 static int
-write_wim_chunks(struct message *msg, filedes_t out_fd,
+write_wim_chunks(struct message *msg, int out_fd,
                 struct chunk_table *chunk_tab)
 {
        for (unsigned i = 0; i < msg->num_chunks; i++) {
@@ -787,7 +787,7 @@ write_wim_chunks(struct message *msg, filedes_t out_fd,
 struct main_writer_thread_ctx {
        struct list_head *stream_list;
        struct wim_lookup_table *lookup_table;
-       filedes_t out_fd;
+       int out_fd;
        int out_ctype;
        int write_resource_flags;
        struct shared_queue *res_to_compress_queue;
@@ -1223,7 +1223,7 @@ get_default_num_threads()
 static int
 write_stream_list_parallel(struct list_head *stream_list,
                           struct wim_lookup_table *lookup_table,
-                          filedes_t out_fd,
+                          int out_fd,
                           int out_ctype,
                           int write_resource_flags,
                           wimlib_progress_func_t progress_func,
@@ -1361,7 +1361,7 @@ out_serial_quiet:
 static int
 write_stream_list(struct list_head *stream_list,
                  struct wim_lookup_table *lookup_table,
-                 filedes_t out_fd, int out_ctype, int write_flags,
+                 int out_fd, int out_ctype, int write_flags,
                  unsigned num_threads, wimlib_progress_func_t progress_func)
 {
        struct wim_lookup_table_entry *lte;
@@ -1805,16 +1805,16 @@ out_close_wim:
                if (ret == 0)
                        ret = WIMLIB_ERR_WRITE;
        }
-       w->out_fd = INVALID_FILEDES;
+       w->out_fd = -1;
        return ret;
 }
 
 #if defined(HAVE_SYS_FILE_H) && defined(HAVE_FLOCK)
 int
-lock_wim(WIMStruct *w, filedes_t fd)
+lock_wim(WIMStruct *w, int fd)
 {
        int ret = 0;
-       if (fd != INVALID_FILEDES && !w->wim_locked) {
+       if (fd != -1 && !w->wim_locked) {
                ret = flock(fd, LOCK_EX | LOCK_NB);
                if (ret != 0) {
                        if (errno == EWOULDBLOCK) {
@@ -1839,7 +1839,7 @@ static int
 open_wim_writable(WIMStruct *w, const tchar *path, int open_flags)
 {
        w->out_fd = topen(path, open_flags | O_BINARY, 0644);
-       if (w->out_fd == INVALID_FILEDES) {
+       if (w->out_fd == -1) {
                ERROR_WITH_ERRNO("Failed to open `%"TS"' for writing", path);
                return WIMLIB_ERR_OPEN;
        }
@@ -1850,10 +1850,10 @@ open_wim_writable(WIMStruct *w, const tchar *path, int open_flags)
 void
 close_wim_writable(WIMStruct *w)
 {
-       if (w->out_fd != INVALID_FILEDES) {
+       if (w->out_fd != -1) {
                if (close(w->out_fd))
                        WARNING_WITH_ERRNO("Failed to close output WIM");
-               w->out_fd = INVALID_FILEDES;
+               w->out_fd = -1;
        }
 }
 
index 23a088e74de2320963091d7e5718cab4ce7c7b2b..da47b28ea3815841e386f6545dd10578d01154ca 100644 (file)
--- a/src/xml.c
+++ b/src/xml.c
@@ -1236,7 +1236,7 @@ libxml_global_cleanup()
  * Reads the XML data from a WIM file.
  */
 int
-read_xml_data(filedes_t in_fd,
+read_xml_data(int in_fd,
              const struct resource_entry *res_entry,
              struct wim_info **info_ret)
 {
index 8840d4ea9fc508d9a4fb20e5be9a75623a38b9fa..d784db145e189f445d013962cab59e736d537ffe 100644 (file)
--- a/src/xml.h
+++ b/src/xml.h
@@ -38,11 +38,11 @@ extern void
 print_image_info(const struct wim_info *wim_info, int image);
 
 extern int
-read_xml_data(filedes_t in_fd, const struct resource_entry *res,
+read_xml_data(int in_fd, const struct resource_entry *res,
              struct wim_info **info_ret);
 
 extern int
-write_xml_data(const struct wim_info *wim_info, int image, filedes_t out_fd,
+write_xml_data(const struct wim_info *wim_info, int image, int out_fd,
               u64 total_bytes, struct resource_entry *out_res_entry);
 
 extern void