cvs: php4 /ext/exif exif.c

From: Date: Thu, 04 Apr 2002 20:45:53 +0000
Subject: cvs: php4 /ext/exif exif.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-10877@lists.php.net to get a copy of this message
helly Thu Apr 4 15:45:53 2002 EDT Modified files: /php4/ext/exif exif.c Log: removed calls to wctomb, wcstombs #leave UNICODE to user Index: php4/ext/exif/exif.c diff -u php4/ext/exif/exif.c:1.81 php4/ext/exif/exif.c:1.82 --- php4/ext/exif/exif.c:1.81 Wed Apr 3 14:50:02 2002 +++ php4/ext/exif/exif.c Thu Apr 4 15:45:53 2002 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: exif.c,v 1.81 2002/04/03 19:50:02 derick Exp $ */ +/* $Id: exif.c,v 1.82 2002/04/04 20:45:53 helly Exp $ */ /* ToDos * @@ -86,11 +86,6 @@ #define FALSE 0 #endif -#ifndef MB_CUR_MAX - #define MB_CUR_MAX 8 - /* Should be a library constant */ -#endif - #ifndef max #define max(a,b) ((a)>(b) ? (a) : (b)) #endif @@ -107,7 +102,7 @@ }; /* }}} */ -#define EXIF_VERSION "1.3 $Id: exif.c,v 1.81 2002/04/03 19:50:02 derick Exp $" +#define EXIF_VERSION "1.3 $Id: exif.c,v 1.82 2002/04/04 20:45:53 helly Exp $" PHP_MINFO_FUNCTION(exif); @@ -1946,6 +1941,23 @@ } /* }}} */ +/* {{{ exif_process_string_raw + * Copy a string in Exif header to a character string returns length of allocated buffer if any. */ +static int exif_process_string_raw(char **result,char *value,size_t byte_count) { + /* we cannot use strlcpy - here the problem is that we have to copy NUL + * chars up to byte_count, we also have to add a single NUL character to + * force end of string. + */ + if (byte_count) { + (*result) = emalloc(byte_count+1); + memcpy(*result, value, byte_count); + (*result)[byte_count] = '\0'; + return byte_count+1; + } + return 0; +} +/* }}} */ + /* {{{ exif_process_string * Copy a string in Exif header to a character string and return length of allocated buffer if any. * In contrast to exif_process_undefined this function does allways return a string buffer */ @@ -1973,33 +1985,15 @@ * Process UserComment in IFD. */ static int exif_process_user_comment(char **pszInfoPtr,char **szEncoding,char *szValuePtr,int ByteCount) { - int a,l; - char mbBuffer[MB_CUR_MAX]; + int a; /* Copy the comment */ if ( ByteCount>=8) { if (!memcmp(szValuePtr, "UNICODE\0", 8)) { - /* treat JIS encoding as if it where UNICODE */ *szEncoding= estrdup((const char*)szValuePtr); szValuePtr = szValuePtr+8; ByteCount -= 8; - l = 0; - a = 0; - while(((wchar_t*)szValuePtr)[a]) { - l += (int)wctomb( mbBuffer, *((wchar_t*)szValuePtr)); - if (sizeof(wchar_t)*a++ >= ByteCount) break; /* avoiding problems with corrupt headers */ - } - if (l>1) { - *pszInfoPtr = emalloc(l+1); - if ( !*pszInfoPtr) { - EXIF_ERRLOG_EALLOC - return 0; - } - wcstombs(*pszInfoPtr, (wchar_t*)(szValuePtr), l+1); - (*pszInfoPtr)[l] = '\0'; - return l+1; - } - return 0; + return exif_process_string_raw(pszInfoPtr, szValuePtr, ByteCount); } else if ( !memcmp(szValuePtr, "ASCII\0\0\0", 8)) { *szEncoding= estrdup((const char*)szValuePtr); @@ -2011,6 +2005,7 @@ *szEncoding= estrdup((const char*)szValuePtr); szValuePtr = szValuePtr+8; ByteCount -= 8; + return exif_process_string_raw(pszInfoPtr, szValuePtr, ByteCount); } else if ( !memcmp(szValuePtr,"\0\0\0\0\0\0\0\0",8)) { /* 8 NULL means undefined and should be ASCII... */ @@ -2024,7 +2019,7 @@ if (ByteCount>0) for (a=ByteCount-1;a && szValuePtr[a]==' ';a--) (szValuePtr)[a] = '\0'; /* normal text without encoding */ - return exif_process_string(pszInfoPtr,szValuePtr,ByteCount); + return exif_process_string(pszInfoPtr, szValuePtr, ByteCount); } /* }}} */

« previous php.cvs (#10877) next »