Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenwmakpath_s.c
Go to the documentation of this file.
00001 /* 00002 * PROJECT: ReactOS CRT library 00003 * LICENSE: See COPYING in the top level directory 00004 * FILE: lib/sdk/crt/stdlib/wmakpath_s.c 00005 * PURPOSE: Creates a path 00006 * PROGRAMMERS: Wine team 00007 * Copyright 1996,1998 Marcus Meissner 00008 * Copyright 1996 Jukka Iivonen 00009 * Copyright 1997,2000 Uwe Bonnes 00010 * Copyright 2000 Jon Griffiths 00011 * 00012 */ 00013 00014 #include <precomp.h> 00015 #include <stdlib.h> 00016 #include <string.h> 00017 00018 /********************************************************************* 00019 * _wmakepath_s (MSVCRT.@) 00020 * 00021 * Safe version of _wmakepath. 00022 */ 00023 int CDECL _wmakepath_s(wchar_t *path, size_t size, const wchar_t *drive, 00024 const wchar_t *directory, const wchar_t *filename, 00025 const wchar_t *extension) 00026 { 00027 wchar_t *p = path; 00028 00029 if (!path || !size) 00030 { 00031 *_errno() = EINVAL; 00032 return EINVAL; 00033 } 00034 00035 if (drive && drive[0]) 00036 { 00037 if (size <= 2) 00038 goto range; 00039 00040 *p++ = drive[0]; 00041 *p++ = ':'; 00042 size -= 2; 00043 } 00044 00045 if (directory && directory[0]) 00046 { 00047 size_t len = strlenW(directory); 00048 unsigned int needs_separator = directory[len - 1] != '/' && directory[len - 1] != '\\'; 00049 size_t copylen = min(size - 1, len); 00050 00051 if (size < 2) 00052 goto range; 00053 00054 memmove(p, directory, copylen * sizeof(wchar_t)); 00055 00056 if (size <= len) 00057 goto range; 00058 00059 p += copylen; 00060 size -= copylen; 00061 00062 if (needs_separator) 00063 { 00064 if (size < 2) 00065 goto range; 00066 00067 *p++ = '\\'; 00068 size -= 1; 00069 } 00070 } 00071 00072 if (filename && filename[0]) 00073 { 00074 size_t len = strlenW(filename); 00075 size_t copylen = min(size - 1, len); 00076 00077 if (size < 2) 00078 goto range; 00079 00080 memmove(p, filename, copylen * sizeof(wchar_t)); 00081 00082 if (size <= len) 00083 goto range; 00084 00085 p += len; 00086 size -= len; 00087 } 00088 00089 if (extension && extension[0]) 00090 { 00091 size_t len = strlenW(extension); 00092 unsigned int needs_period = extension[0] != '.'; 00093 size_t copylen; 00094 00095 if (size < 2) 00096 goto range; 00097 00098 if (needs_period) 00099 { 00100 *p++ = '.'; 00101 size -= 1; 00102 } 00103 00104 copylen = min(size - 1, len); 00105 memcpy(p, extension, copylen * sizeof(wchar_t)); 00106 00107 if (size <= len) 00108 goto range; 00109 00110 p += copylen; 00111 } 00112 00113 *p = '\0'; 00114 return 0; 00115 00116 range: 00117 path[0] = '\0'; 00118 *_errno() = ERANGE; 00119 return ERANGE; 00120 } 00121 Generated on Fri May 25 2012 04:34:59 for ReactOS by
1.7.6.1
|