mirror of
				https://github.com/pbatard/rufus.git
				synced 2024-08-14 23:57:05 +00:00 
			
		
		
		
	[iso9660] add Joliet support (that doesn't rely on iconv)
* also _stat64 -> _stati64
This commit is contained in:
		
							parent
							
								
									a9383b6997
								
							
						
					
					
						commit
						0ccc6f71df
					
				
					 9 changed files with 326 additions and 13 deletions
				
			
		|  | @ -35,7 +35,7 @@ | |||
| 
 | ||||
| /* Define 1 if you want ISO-9660 Joliet extension support. You must have also
 | ||||
|    libiconv installed to get Joliet extension support. */ | ||||
| #undef HAVE_JOLIET | ||||
| #define HAVE_JOLIET 1 | ||||
| 
 | ||||
| /* Define to 1 if you have the `memcpy' function. */ | ||||
| #define HAVE_MEMCPY 1 | ||||
|  |  | |||
|  | @ -192,9 +192,9 @@ cdio_stdio_new(const char pathname[]) | |||
|   CdioDataSource_t *new_obj = NULL; | ||||
|   cdio_stream_io_functions funcs = { NULL, NULL, NULL, NULL, NULL, NULL }; | ||||
|   _UserData *ud = NULL; | ||||
|   struct _stat64 statbuf; | ||||
|   struct _stati64 statbuf; | ||||
|    | ||||
|   if (_stat64 (pathname, &statbuf) == -1)  | ||||
|   if (_stati64 (pathname, &statbuf) == -1)  | ||||
|     { | ||||
|       cdio_warn ("could not retrieve file info for `%s': %s",  | ||||
|                  pathname, strerror (errno)); | ||||
|  |  | |||
|  | @ -26,6 +26,7 @@ | |||
|     <ClCompile Include="..\iso9660.c" /> | ||||
|     <ClCompile Include="..\iso9660_fs.c" /> | ||||
|     <ClCompile Include="..\rock.c" /> | ||||
|     <ClCompile Include="..\utf8.c" /> | ||||
|     <ClCompile Include="..\xa.c" /> | ||||
|   </ItemGroup> | ||||
|   <PropertyGroup Label="Globals"> | ||||
|  |  | |||
|  | @ -31,5 +31,8 @@ | |||
|     <ClCompile Include="..\iso9660.c"> | ||||
|       <Filter>Source Files</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="..\utf8.c"> | ||||
|       <Filter>Source Files</Filter> | ||||
|     </ClCompile> | ||||
|   </ItemGroup> | ||||
| </Project> | ||||
|  | @ -1,3 +1,3 @@ | |||
| noinst_LIBRARIES = libiso9660.a | ||||
| libiso9660_a_SOURCES = iso9660.c iso9660_fs.c rock.c xa.c | ||||
| libiso9660_a_SOURCES = iso9660.c iso9660_fs.c rock.c xa.c utf8.c | ||||
| libiso9660_a_CFLAGS = -I. -I.. -I../driver $(AM_CFLAGS) | ||||
|  |  | |||
|  | @ -54,7 +54,7 @@ libiso9660_a_AR = $(AR) $(ARFLAGS) | |||
| libiso9660_a_LIBADD = | ||||
| am_libiso9660_a_OBJECTS = libiso9660_a-iso9660.$(OBJEXT) \
 | ||||
| 	libiso9660_a-iso9660_fs.$(OBJEXT) libiso9660_a-rock.$(OBJEXT) \
 | ||||
| 	libiso9660_a-xa.$(OBJEXT) | ||||
| 	libiso9660_a-xa.$(OBJEXT) libiso9660_a-utf8.$(OBJEXT) | ||||
| libiso9660_a_OBJECTS = $(am_libiso9660_a_OBJECTS) | ||||
| DEFAULT_INCLUDES = -I.@am__isrc@ | ||||
| depcomp = | ||||
|  | @ -167,7 +167,7 @@ top_build_prefix = @top_build_prefix@ | |||
| top_builddir = @top_builddir@ | ||||
| top_srcdir = @top_srcdir@ | ||||
| noinst_LIBRARIES = libiso9660.a | ||||
| libiso9660_a_SOURCES = iso9660.c iso9660_fs.c rock.c xa.c | ||||
| libiso9660_a_SOURCES = iso9660.c iso9660_fs.c rock.c xa.c utf8.c | ||||
| libiso9660_a_CFLAGS = -I. -I.. -I../driver $(AM_CFLAGS) | ||||
| all: all-am | ||||
| 
 | ||||
|  | @ -257,6 +257,14 @@ libiso9660_a-xa.obj: xa.c | |||
| 	$(AM_V_CC) @AM_BACKSLASH@ | ||||
| 	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libiso9660_a_CFLAGS) $(CFLAGS) -c -o libiso9660_a-xa.obj `if test -f 'xa.c'; then $(CYGPATH_W) 'xa.c'; else $(CYGPATH_W) '$(srcdir)/xa.c'; fi` | ||||
| 
 | ||||
| libiso9660_a-utf8.o: utf8.c | ||||
| 	$(AM_V_CC) @AM_BACKSLASH@ | ||||
| 	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libiso9660_a_CFLAGS) $(CFLAGS) -c -o libiso9660_a-utf8.o `test -f 'utf8.c' || echo '$(srcdir)/'`utf8.c | ||||
| 
 | ||||
| libiso9660_a-utf8.obj: utf8.c | ||||
| 	$(AM_V_CC) @AM_BACKSLASH@ | ||||
| 	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libiso9660_a_CFLAGS) $(CFLAGS) -c -o libiso9660_a-utf8.obj `if test -f 'utf8.c'; then $(CYGPATH_W) 'utf8.c'; else $(CYGPATH_W) '$(srcdir)/utf8.c'; fi` | ||||
| 
 | ||||
| ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) | ||||
| 	list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
 | ||||
| 	unique=`for i in $$list; do \
 | ||||
|  |  | |||
|  | @ -797,7 +797,7 @@ _iso9660_dir_to_statbuf (iso9660_dir_t *p_iso9660_dir, bool_3way_t b_xa, | |||
|       else if (i_joliet_level) { | ||||
| 	int i_inlen = i_fname; | ||||
| 	cdio_utf8_t *p_psz_out = NULL; | ||||
| 	if (cdio_charset_to_utf8(p_iso9660_dir->filename, i_inlen, | ||||
| 	if (cdio_charset_to_utf8(&p_iso9660_dir->filename.str[1], i_inlen, | ||||
|                              &p_psz_out, "UCS-2BE")) { | ||||
|           strncpy(p_stat->filename, p_psz_out, i_fname); | ||||
|           free(p_psz_out); | ||||
|  |  | |||
							
								
								
									
										301
									
								
								src/libcdio/iso9660/utf8.c
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										301
									
								
								src/libcdio/iso9660/utf8.c
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,301 @@ | |||
| /*
 | ||||
|   Copyright (C) 2006, 2008 Burkhard Plaum <plaum@ipf.uni-stuttgart.de> | ||||
|   Copyright (C) 2011 Rocky Bernstein <rocky@gnu.org> | ||||
| 
 | ||||
|   This program is free software: you can redistribute it and/or modify | ||||
|   it under the terms of the GNU General Public License as published by | ||||
|   the Free Software Foundation, either version 3 of the License, or | ||||
|   (at your option) any later version. | ||||
| 
 | ||||
|   This program is distributed in the hope that it will be useful, | ||||
|   but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|   GNU General Public License for more details. | ||||
| 
 | ||||
|   You should have received a copy of the GNU General Public License | ||||
|   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | ||||
| */ | ||||
| /* UTF-8 support */ | ||||
|  | ||||
| #if defined(HAVE_CONFIG_H) && !defined(__CDIO_CONFIG_H__) | ||||
| # include <config.h> | ||||
| # define __CDIO_CONFIG_H__ 1 | ||||
| #else | ||||
| #ifndef EXTERNAL_LIBCDIO_CONFIG_H | ||||
| #define EXTERNAL_LIBCDIO_CONFIG_H | ||||
| #include <cdio/cdio_config.h> | ||||
| #endif | ||||
| #endif | ||||
| 
 | ||||
| #ifdef HAVE_JOLIET | ||||
| #ifdef HAVE_STRING_H | ||||
| # include <string.h> | ||||
| #endif | ||||
| 
 | ||||
| #ifdef HAVE_STDLIB_H | ||||
| #include <stdlib.h> | ||||
| #endif | ||||
| 
 | ||||
| #ifdef HAVE_ERRNO_H | ||||
| #include <errno.h> | ||||
| #endif | ||||
| 
 | ||||
| #include <cdio/utf8.h> | ||||
| 
 | ||||
| #include <stdio.h> | ||||
| 
 | ||||
| #ifdef HAVE_ICONV | ||||
| #include <iconv.h> | ||||
| struct cdio_charset_coverter_s | ||||
|   { | ||||
|   iconv_t ic; | ||||
|   }; | ||||
| 
 | ||||
| cdio_charset_coverter_t * | ||||
| cdio_charset_converter_create(const char * src_charset, | ||||
|                               const char * dst_charset) | ||||
|   { | ||||
|   cdio_charset_coverter_t * ret; | ||||
|   ret = calloc(1, sizeof(*ret)); | ||||
|   ret->ic = iconv_open(dst_charset, src_charset); | ||||
|   return ret; | ||||
|   } | ||||
| 
 | ||||
| #if 0 | ||||
| static void bgav_hexdump(uint8_t * data, int len, int linebreak) | ||||
|   { | ||||
|   int i; | ||||
|   int bytes_written = 0; | ||||
|   int imax; | ||||
|    | ||||
|   while(bytes_written < len) | ||||
|     { | ||||
|     imax = (bytes_written + linebreak > len) ? len - bytes_written : linebreak; | ||||
|     for(i = 0; i < imax; i++) | ||||
|       fprintf(stderr, "%02x ", data[bytes_written + i]); | ||||
|     for(i = imax; i < linebreak; i++) | ||||
|       fprintf(stderr, "   "); | ||||
|     for(i = 0; i < imax; i++) | ||||
|       { | ||||
|       if(!(data[bytes_written + i] & 0x80) && (data[bytes_written + i] >= 32)) | ||||
|         fprintf(stderr, "%c", data[bytes_written + i]); | ||||
|       else | ||||
|         fprintf(stderr, "."); | ||||
|       } | ||||
|     bytes_written += imax; | ||||
|     fprintf(stderr, "\n"); | ||||
|     } | ||||
|   } | ||||
| #endif | ||||
| 
 | ||||
| void cdio_charset_converter_destroy(cdio_charset_coverter_t*cnv) | ||||
|   { | ||||
|   iconv_close(cnv->ic); | ||||
|   free(cnv); | ||||
|   } | ||||
| 
 | ||||
| #define BYTES_INCREMENT 16 | ||||
| 
 | ||||
| static bool | ||||
| do_convert(iconv_t cd, char * src, int src_len, | ||||
|            char ** dst, int *dst_len) | ||||
|   { | ||||
|   char * ret; | ||||
| 
 | ||||
|   char *inbuf; | ||||
|   char *outbuf; | ||||
|   int alloc_size; | ||||
|   int output_pos; | ||||
|   size_t inbytesleft; | ||||
|   size_t outbytesleft; | ||||
| 
 | ||||
|   if(src_len < 0) | ||||
|     src_len = strlen(src); | ||||
| #if 0 | ||||
|   fprintf(stderr, "Converting:\n"); | ||||
|   bgav_hexdump(src, src_len, 16); | ||||
| #endif     | ||||
|   alloc_size = src_len + BYTES_INCREMENT; | ||||
| 
 | ||||
|   inbytesleft  = src_len; | ||||
|    | ||||
|   /* We reserve space here to add a final '\0' */ | ||||
|   outbytesleft = alloc_size-1; | ||||
| 
 | ||||
|   ret    = malloc(alloc_size); | ||||
| 
 | ||||
|   inbuf  = src; | ||||
|   outbuf = ret; | ||||
|    | ||||
|   while(1) | ||||
|     { | ||||
|      | ||||
|     if(iconv(cd, (ICONV_CONST char **)&inbuf, &inbytesleft, | ||||
|              &outbuf, &outbytesleft) == (size_t)-1) | ||||
|       { | ||||
|       switch(errno) | ||||
|         { | ||||
|         case E2BIG: | ||||
|           output_pos = (int)(outbuf - ret); | ||||
| 
 | ||||
|           alloc_size   += BYTES_INCREMENT; | ||||
|           outbytesleft += BYTES_INCREMENT; | ||||
| 
 | ||||
|           ret = realloc(ret, alloc_size); | ||||
|           if (ret == NULL) | ||||
|             { | ||||
|             fprintf(stderr, "Can't realloc(%d).\n", alloc_size); | ||||
|             return false; | ||||
|             } | ||||
|           outbuf = ret + output_pos; | ||||
|           break; | ||||
|         default: | ||||
|           fprintf(stderr, "Iconv failed: %s\n", strerror(errno)); | ||||
|           if (ret != NULL) | ||||
|             free(ret); | ||||
|           return false; | ||||
|           break; | ||||
|         } | ||||
|       } | ||||
|     if(!inbytesleft) | ||||
|       break; | ||||
|     } | ||||
|   /* Zero terminate */ | ||||
|   *outbuf = '\0'; | ||||
| 
 | ||||
|   /* Set return values */ | ||||
|   *dst = ret; | ||||
|   if(dst_len) | ||||
|     *dst_len = (int)(outbuf - ret); | ||||
| #if 0 | ||||
|   fprintf(stderr, "Conversion done, src:\n"); | ||||
|   bgav_hexdump(src, src_len, 16); | ||||
|   fprintf(stderr, "dst:\n"); | ||||
|   bgav_hexdump((uint8_t*)(ret), (int)(outbuf - ret), 16); | ||||
| #endif   | ||||
|   return true; | ||||
|   } | ||||
| 
 | ||||
| bool cdio_charset_convert(cdio_charset_coverter_t*cnv, | ||||
|                           char * src, int src_len, | ||||
|                           char ** dst, int * dst_len) | ||||
|   { | ||||
|   return do_convert(cnv->ic, src, src_len, dst, dst_len); | ||||
|   } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| bool cdio_charset_from_utf8(cdio_utf8_t * src, char ** dst, | ||||
|                             int * dst_len, const char * dst_charset) | ||||
|   { | ||||
|   iconv_t ic; | ||||
|   bool result; | ||||
|   ic = iconv_open(dst_charset, "UTF-8"); | ||||
|   result = do_convert(ic, src, -1, dst, dst_len); | ||||
|   iconv_close(ic); | ||||
|   return result; | ||||
|   } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| bool cdio_charset_to_utf8(char *src, size_t src_len, cdio_utf8_t **dst, | ||||
|                           const char * src_charset) | ||||
|   { | ||||
|   iconv_t ic; | ||||
|   bool result; | ||||
|   ic = iconv_open("UTF-8", src_charset); | ||||
|   result = do_convert(ic, src, src_len, dst, NULL); | ||||
|   iconv_close(ic); | ||||
|   return result; | ||||
|   } | ||||
| #elif defined(_WIN32) | ||||
| #include <windows.h> | ||||
| 
 | ||||
| #define wchar_to_utf8_no_alloc(wsrc, dest, dest_size) \ | ||||
| 	WideCharToMultiByte(CP_UTF8, 0, wsrc, -1, dest, dest_size, NULL, NULL) | ||||
| #define utf8_to_wchar_no_alloc(src, wdest, wdest_size) \ | ||||
| 	MultiByteToWideChar(CP_UTF8, 0, src, -1, wdest, wdest_size) | ||||
| 
 | ||||
| /*
 | ||||
|  * Converts an UTF-16 string to UTF8 (allocate returned string) | ||||
|  * Returns NULL on error | ||||
|  */ | ||||
| static __inline char* wchar_to_utf8(const wchar_t* wstr) | ||||
| { | ||||
| 	int size = 0; | ||||
| 	char* str = NULL; | ||||
| 
 | ||||
| 	// Find out the size we need to allocate for our converted string
 | ||||
| 	size = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, NULL, 0, NULL, NULL); | ||||
| 	if (size <= 1)	// An empty string would be size 1
 | ||||
| 		return NULL; | ||||
| 
 | ||||
| 	if ((str = (char*)calloc(size, 1)) == NULL) | ||||
| 		return NULL; | ||||
| 
 | ||||
| 	if (wchar_to_utf8_no_alloc(wstr, str, size) != size) { | ||||
| 		free(str); | ||||
| 		return NULL; | ||||
| 	} | ||||
| 
 | ||||
| 	return str; | ||||
| } | ||||
| 
 | ||||
| /*
 | ||||
|  * Converts an UTF8 string to UTF-16 (allocate returned string) | ||||
|  * Returns NULL on error | ||||
|  */ | ||||
| static __inline wchar_t* utf8_to_wchar(const char* str) | ||||
| { | ||||
| 	int size = 0; | ||||
| 	wchar_t* wstr = NULL; | ||||
| 
 | ||||
| 	// Find out the size we need to allocate for our converted string
 | ||||
| 	size = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0); | ||||
| 	if (size <= 1)	// An empty string would be size 1
 | ||||
| 		return NULL; | ||||
| 
 | ||||
| 	if ((wstr = (wchar_t*)calloc(size, sizeof(wchar_t))) == NULL) | ||||
| 		return NULL; | ||||
| 
 | ||||
| 	if (utf8_to_wchar_no_alloc(str, wstr, size) != size) { | ||||
| 		free(wstr); | ||||
| 		return NULL; | ||||
| 	} | ||||
| 	return wstr; | ||||
| } | ||||
| 
 | ||||
| bool cdio_charset_to_utf8(char *src, size_t src_len, cdio_utf8_t **dst, | ||||
|                           const char * src_charset) | ||||
| { | ||||
| 	wchar_t* le_src; | ||||
| 
 | ||||
| 	if (src == NULL || dst == NULL || src_charset == NULL || strcmp(src_charset, "UCS-2BE") != 0) | ||||
| 		return false; | ||||
| 
 | ||||
| 	if (src_len < 0) { | ||||
| 		for (src_len = 0; ((uint16_t*)src)[src_len] !=0; src_len++); | ||||
| 		src_len <<=2; | ||||
| 	} | ||||
| 
 | ||||
| 	// zero lenght is a headache (LCMapString doesn't support it)
 | ||||
| 	// => eliminate this case first
 | ||||
| 	if (src_len == 0) { | ||||
| 		*dst = (cdio_utf8_t*)malloc(1); | ||||
| 		*dst[0] = 0; | ||||
| 		return true; | ||||
| 	} | ||||
| 
 | ||||
| 	le_src = (wchar_t*)malloc(src_len+2); | ||||
| 	// WideCharToMultiByte only takes UCS-2LE, and we are fed UCS-2BE 
 | ||||
| 	// => perform byte reversal
 | ||||
| 	LCMapStringW(0, LCMAP_BYTEREV, (LPCWSTR)src, src_len, le_src, src_len); | ||||
| 	*dst = wchar_to_utf8(le_src); | ||||
| 	free(le_src); | ||||
| 
 | ||||
| 	return (*dst != NULL); | ||||
| } | ||||
| #endif /* HAVE_ICONV */ | ||||
| 
 | ||||
| #endif /* HAVE_JOLIET */ | ||||
							
								
								
									
										12
									
								
								src/rufus.rc
									
										
									
									
									
								
							
							
						
						
									
										12
									
								
								src/rufus.rc
									
										
									
									
									
								
							|  | @ -33,7 +33,7 @@ LANGUAGE LANG_ENGLISH, SUBLANG_NEUTRAL | |||
| IDD_DIALOG DIALOGEX 12, 12, 206, 278 | ||||
| STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU | ||||
| EXSTYLE WS_EX_APPWINDOW | ||||
| CAPTION "Rufus v1.0.7.138" | ||||
| CAPTION "Rufus v1.0.7.139" | ||||
| FONT 8, "MS Shell Dlg", 400, 0, 0x1 | ||||
| BEGIN | ||||
|     DEFPUSHBUTTON   "Start",IDC_START,94,236,50,14 | ||||
|  | @ -70,7 +70,7 @@ BEGIN | |||
|     DEFPUSHBUTTON   "OK",IDOK,231,175,50,14,WS_GROUP | ||||
|     CONTROL         "<a href=""http://rufus.akeo.ie"">http://rufus.akeo.ie</a>",IDC_ABOUT_RUFUS_URL, | ||||
|                     "SysLink",WS_TABSTOP,46,47,114,9 | ||||
|     LTEXT           "Version 1.0.7 (Build 138)",IDC_STATIC,46,19,78,8 | ||||
|     LTEXT           "Version 1.0.7 (Build 139)",IDC_STATIC,46,19,78,8 | ||||
|     PUSHBUTTON      "License...",IDC_ABOUT_LICENSE,46,175,50,14,WS_GROUP | ||||
|     EDITTEXT        IDC_ABOUT_COPYRIGHTS,46,107,235,63,ES_MULTILINE | ES_READONLY | WS_VSCROLL | ||||
|     LTEXT           "Report bugs or request enhancements at:",IDC_STATIC,46,66,187,8 | ||||
|  | @ -208,8 +208,8 @@ END | |||
| // | ||||
| 
 | ||||
| VS_VERSION_INFO VERSIONINFO | ||||
|  FILEVERSION 1,0,7,138 | ||||
|  PRODUCTVERSION 1,0,7,138 | ||||
|  FILEVERSION 1,0,7,139 | ||||
|  PRODUCTVERSION 1,0,7,139 | ||||
|  FILEFLAGSMASK 0x3fL | ||||
| #ifdef _DEBUG | ||||
|  FILEFLAGS 0x1L | ||||
|  | @ -226,13 +226,13 @@ BEGIN | |||
|         BEGIN | ||||
|             VALUE "CompanyName", "akeo.ie" | ||||
|             VALUE "FileDescription", "Rufus" | ||||
|             VALUE "FileVersion", "1.0.7.138" | ||||
|             VALUE "FileVersion", "1.0.7.139" | ||||
|             VALUE "InternalName", "Rufus" | ||||
|             VALUE "LegalCopyright", "© 2011 Pete Batard (GPL v3)" | ||||
|             VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html" | ||||
|             VALUE "OriginalFilename", "rufus.exe" | ||||
|             VALUE "ProductName", "Rufus" | ||||
|             VALUE "ProductVersion", "1.0.7.138" | ||||
|             VALUE "ProductVersion", "1.0.7.139" | ||||
|         END | ||||
|     END | ||||
|     BLOCK "VarFileInfo" | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue