|
352 | 352 | #define lseek _lseeki64
|
353 | 353 | #define mkdir(a, b) _mkdir(a)
|
354 | 354 | #define stat _stat64
|
| 355 | + #define lstat _stat64 |
355 | 356 | #define realpath(a, b) _fullpath(b, a, _MAX_PATH)
|
356 | 357 |
|
357 | 358 | #define bswap_16(x) _byteswap_ushort(x)
|
@@ -986,35 +987,39 @@ int create_xiso( char *in_root_directory, const char *in_output_directory, dir_n
|
986 | 987 | write_tree_context wt_context = { 0 };
|
987 | 988 | uint32_t start_sector = 0;
|
988 | 989 | int i = 0, n = 0, xiso = -1, err = 0;
|
989 |
| - char *cwd = NULL, *iso_name = NULL, *xiso_path = NULL, *iso_dir = NULL, *real_path = NULL; |
| 990 | + char *cwd = NULL, *iso_name = NULL, *xiso_path = NULL, *iso_dir = NULL, *real_path = NULL, *in_dir_path = NULL; |
990 | 991 |
|
991 | 992 | s_total_bytes = s_total_files = 0;
|
992 | 993 |
|
993 | 994 | if ( ( cwd = getcwd( NULL, 0 ) ) == NULL ) mem_err();
|
994 |
| - if ( ! err ) { |
995 |
| - if ( ! in_root ) { |
996 |
| - i = (int)strlen(in_root_directory) - 1; |
997 |
| - if ( in_root_directory[i] == '/' || in_root_directory[i] == '\\' ) in_root_directory[i] = 0; |
998 |
| - if ((iso_dir = strrchr(in_root_directory, PATH_CHAR))) iso_dir++; |
999 |
| - else iso_dir = in_root_directory; |
1000 |
| - |
1001 |
| - iso_name = in_name ? in_name : iso_dir; |
1002 |
| - } else { |
| 995 | + if (!err) { |
| 996 | + if (!in_root) { |
| 997 | + if ((in_dir_path = realpath(in_root_directory, NULL)) == NULL) misc_err("unable to get absolute path of %s: %s", in_root_directory, strerror(errno)); |
| 998 | + if (!err) { |
| 999 | + // Remember not to free in_dir_path until iso_dir is not needed anymore |
| 1000 | + if ((iso_dir = strrchr(in_dir_path, PATH_CHAR)) != NULL) iso_dir++; |
| 1001 | + else iso_dir = in_dir_path; |
| 1002 | + iso_name = in_name ? in_name : iso_dir; |
| 1003 | + } |
| 1004 | + } |
| 1005 | + else { |
1003 | 1006 | iso_dir = iso_name = in_root_directory;
|
1004 | 1007 | }
|
1005 | 1008 | }
|
1006 |
| - if ( ! err ) { |
1007 |
| - if ( ! *iso_dir ) iso_dir = PATH_CHAR_STR; |
1008 |
| - if ( ! iso_name || ! *iso_name ) iso_name = "root"; |
1009 |
| - else if ( iso_name[ 1 ] == ':' ) { iso_name[ 1 ] = iso_name[ 0 ]; ++iso_name; } |
1010 |
| - if (!err && (real_path = realpath(in_output_directory ? in_output_directory : ".", NULL)) == NULL) misc_err("unable to get absolute path of %s: %s", real_path, strerror(errno)); |
| 1009 | + if(!err) { |
| 1010 | + if (!iso_dir || !*iso_dir) iso_dir = PATH_CHAR_STR; |
| 1011 | + if (!iso_name || !*iso_name) iso_name = "root"; |
| 1012 | + else if (iso_name[1] == ':') { iso_name[1] = iso_name[0]; ++iso_name; } |
| 1013 | + |
| 1014 | + if (in_output_directory == NULL) in_output_directory = "."; |
| 1015 | + if (!err && (real_path = realpath(in_output_directory, NULL)) == NULL) misc_err("unable to get absolute path of %s: %s", in_output_directory, strerror(errno)); |
1011 | 1016 | if (!err && (asprintf(&xiso_path, "%s%c%s%s", real_path, PATH_CHAR, iso_name, in_name ? "" : ".iso")) == -1) mem_err();
|
1012 | 1017 | if (real_path) {
|
1013 | 1018 | free(real_path);
|
1014 | 1019 | real_path = NULL;
|
1015 | 1020 | }
|
1016 | 1021 |
|
1017 |
| - if (!err && !in_root && chdir(in_root_directory) == -1) chdir_err(in_root_directory); |
| 1022 | + if (!err && !in_root && chdir(in_dir_path) == -1) chdir_err(in_dir_path); |
1018 | 1023 | }
|
1019 | 1024 | if ( ! err ) {
|
1020 | 1025 | exiso_log( "\n%s %s%s:\n", in_root ? "rewriting" : "creating", iso_name, in_name ? "" : ".iso" );
|
@@ -1090,7 +1095,7 @@ int create_xiso( char *in_root_directory, const char *in_output_directory, dir_n
|
1090 | 1095 | if ( ! err && write( xiso, XISO_HEADER_DATA, XISO_HEADER_DATA_LENGTH ) != XISO_HEADER_DATA_LENGTH ) write_err();
|
1091 | 1096 |
|
1092 | 1097 | if ( ! err && ! in_root ) {
|
1093 |
| - if ( chdir( ".." ) == -1 ) chdir_err( ".." ); |
| 1098 | + if (chdir("..") == -1) chdir_err(".."); |
1094 | 1099 | }
|
1095 | 1100 | if (!err && (root.filename = strdup(iso_dir)) == NULL) mem_err();
|
1096 | 1101 | if (!err) {
|
@@ -1138,6 +1143,11 @@ int create_xiso( char *in_root_directory, const char *in_output_directory, dir_n
|
1138 | 1143 | if (root.filename) free(root.filename);
|
1139 | 1144 | if (root.filename_cp1252) free(root.filename_cp1252);
|
1140 | 1145 |
|
| 1146 | + if (in_dir_path) { |
| 1147 | + free(in_dir_path); |
| 1148 | + in_dir_path = NULL; |
| 1149 | + } |
| 1150 | + |
1141 | 1151 | if ( cwd ) {
|
1142 | 1152 | if ( chdir( cwd ) == -1 ) chdir_err( cwd );
|
1143 | 1153 | free( cwd );
|
@@ -2032,7 +2042,7 @@ int generate_avl_tree_local( dir_node_avl **out_root, int *io_n ) {
|
2032 | 2042 | avl->filename = NULL;
|
2033 | 2043 | } else if ((avl->filename_cp1252 = getCP1252String(p->d_name)) == NULL) mem_err();
|
2034 | 2044 | }
|
2035 |
| - if ( ! err && stat( p->d_name, &sb ) == -1 ) read_err(); |
| 2045 | + if ( ! err && lstat( p->d_name, &sb ) == -1 ) read_err(); |
2036 | 2046 | if ( ! err ) {
|
2037 | 2047 | if ( S_ISDIR( sb.st_mode ) ) {
|
2038 | 2048 | empty_dir = false;
|
|
0 commit comments