From 813825fd27b9d2b698fc0b3611d82d016ec0647f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9=20van=20Geldorp?= Date: Mon, 8 Dec 2003 10:25:26 +0000 Subject: [PATCH] Handle NULL fname svn path=/trunk/; revision=6909 --- reactos/lib/msvcrt/stdlib/splitp.c | 81 +++++++++++++++++------------ reactos/lib/msvcrt/stdlib/wsplitp.c | 80 +++++++++++++++++----------- 2 files changed, 98 insertions(+), 63 deletions(-) diff --git a/reactos/lib/msvcrt/stdlib/splitp.c b/reactos/lib/msvcrt/stdlib/splitp.c index 229868a3c6c..b523c9514ab 100644 --- a/reactos/lib/msvcrt/stdlib/splitp.c +++ b/reactos/lib/msvcrt/stdlib/splitp.c @@ -7,46 +7,63 @@ */ void _splitpath(const char* path, char* drive, char* dir, char* fname, char* ext) { - char* tmp_drive; - char* tmp_dir; - char* tmp_ext; + char* tmp_drive; + char* tmp_dir; + char* tmp_ext; - tmp_drive = (char*)strchr(path,':'); - if (drive) { - if (tmp_drive) { - strncpy(drive,tmp_drive-1,2); - *(drive+2) = 0; - } else { - *drive = 0; - } + tmp_drive = (char*)strchr(path,':'); + if (drive) + { + if (tmp_drive) + { + strncpy(drive,tmp_drive-1,2); + *(drive+2) = 0; + } + else + { + *drive = 0; + } } - if (!tmp_drive) { - tmp_drive = (char*)path - 1; + if (!tmp_drive) + { + tmp_drive = (char*)path - 1; } - tmp_dir = (char*)strrchr(path,'\\'); - if (dir) { - if (tmp_dir) { - strncpy(dir,tmp_drive+1,tmp_dir-tmp_drive); - *(dir+(tmp_dir-tmp_drive)) = 0; - } else { - *dir =0; - } + tmp_dir = (char*)strrchr(path,'\\'); + if (dir) + { + if (tmp_dir) + { + strncpy(dir,tmp_drive+1,tmp_dir-tmp_drive); + *(dir+(tmp_dir-tmp_drive)) = 0; + } + else + { + *dir =0; + } } - tmp_ext = (char*)strrchr(path,'.'); - if (!tmp_ext) { - tmp_ext = (char*)path+strlen(path); + tmp_ext = (char*)strrchr(path,'.'); + if (!tmp_ext) + { + tmp_ext = (char*)path+strlen(path); } - if (ext) { - strcpy(ext,tmp_ext); + if (ext) + { + strcpy(ext,tmp_ext); } - if (tmp_dir) { - strncpy(fname,tmp_dir+1,tmp_ext-tmp_dir-1); - *(fname+(tmp_ext-tmp_dir-1)) = 0; - } else { - strncpy(fname,tmp_drive+1,tmp_ext-tmp_drive-1); - *(fname+(tmp_ext-path))=0; + if (fname) + { + if (tmp_dir) + { + strncpy(fname,tmp_dir+1,tmp_ext-tmp_dir-1); + *(fname+(tmp_ext-tmp_dir-1)) = 0; + } + else + { + strncpy(fname,tmp_drive+1,tmp_ext-tmp_drive-1); + *(fname+(tmp_ext-path))=0; + } } } diff --git a/reactos/lib/msvcrt/stdlib/wsplitp.c b/reactos/lib/msvcrt/stdlib/wsplitp.c index 07f72d0d685..8a3520884b7 100644 --- a/reactos/lib/msvcrt/stdlib/wsplitp.c +++ b/reactos/lib/msvcrt/stdlib/wsplitp.c @@ -7,45 +7,63 @@ */ void _wsplitpath(const wchar_t* path, wchar_t* drive, wchar_t* dir, wchar_t* fname, wchar_t* ext) { - wchar_t* tmp_drive; - wchar_t* tmp_dir; - wchar_t* tmp_ext; + wchar_t* tmp_drive; + wchar_t* tmp_dir; + wchar_t* tmp_ext; - tmp_drive = (wchar_t*)wcschr(path,L':'); - if (drive) { - if (tmp_drive) { - wcsncpy(drive,tmp_drive-1,2); - *(drive+2) = 0; - } else { - *drive = 0; - } + tmp_drive = (wchar_t*)wcschr(path,L':'); + if (drive) + { + if (tmp_drive) + { + wcsncpy(drive,tmp_drive-1,2); + *(drive+2) = 0; + } + else + { + *drive = 0; + } } - if (!tmp_drive) { - tmp_drive = (wchar_t*)path - 1; + if (!tmp_drive) + { + tmp_drive = (wchar_t*)path - 1; } - tmp_dir = (wchar_t*)wcsrchr(path,L'\\'); - if (dir) { - if (tmp_dir) { - wcsncpy(dir,tmp_drive+1,tmp_dir-tmp_drive); - *(dir+(tmp_dir-tmp_drive)) = 0; - } else - *dir =0; + tmp_dir = (wchar_t*)wcsrchr(path,L'\\'); + if (dir) + { + if (tmp_dir) + { + wcsncpy(dir,tmp_drive+1,tmp_dir-tmp_drive); + *(dir+(tmp_dir-tmp_drive)) = 0; + } + else + { + *dir =0; + } } - tmp_ext = (wchar_t*)wcsrchr(path,L'.'); - if (!tmp_ext) { - tmp_ext = (wchar_t*)path+wcslen(path); + tmp_ext = (wchar_t*)wcsrchr(path,L'.'); + if (! tmp_ext) + { + tmp_ext = (wchar_t*)path+wcslen(path); } - if (ext) { - wcscpy(ext,tmp_ext); + if (ext) + { + wcscpy(ext,tmp_ext); } - if (tmp_dir) { - wcsncpy(fname,tmp_dir+1,tmp_ext-tmp_dir-1); - *(fname+(tmp_ext-tmp_dir-1)) = 0; - } else { - wcsncpy(fname,tmp_drive+1,tmp_ext-tmp_drive-1); - *(fname+(tmp_ext-path))=0; + if (fname) + { + if (tmp_dir) + { + wcsncpy(fname,tmp_dir+1,tmp_ext-tmp_dir-1); + *(fname+(tmp_ext-tmp_dir-1)) = 0; + } + else + { + wcsncpy(fname,tmp_drive+1,tmp_ext-tmp_drive-1); + *(fname+(tmp_ext-path))=0; + } } }