mirror of
https://github.com/reactos/reactos.git
synced 2025-06-27 12:49:42 +00:00
Create a branch for cmake bringup.
svn path=/branches/cmake-bringup/; revision=48236
This commit is contained in:
parent
a28e798006
commit
c424146e2c
20602 changed files with 0 additions and 1140137 deletions
120
lib/sdk/crt/stdlib/makepath_s.c
Normal file
120
lib/sdk/crt/stdlib/makepath_s.c
Normal file
|
@ -0,0 +1,120 @@
|
|||
/*
|
||||
* PROJECT: ReactOS CRT library
|
||||
* LICENSE: See COPYING in the top level directory
|
||||
* FILE: lib/sdk/crt/stdlib/makepath_s.c
|
||||
* PURPOSE: Creates a path
|
||||
* PROGRAMMERS: Wine team
|
||||
* Copyright 1996,1998 Marcus Meissner
|
||||
* Copyright 1996 Jukka Iivonen
|
||||
* Copyright 1997,2000 Uwe Bonnes
|
||||
* Copyright 2000 Jon Griffiths
|
||||
*
|
||||
*/
|
||||
|
||||
#include <precomp.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/*********************************************************************
|
||||
* _makepath_s (MSVCRT.@)
|
||||
*
|
||||
* Safe version of _makepath.
|
||||
*/
|
||||
int CDECL _makepath_s(char *path, size_t size, const char *drive,
|
||||
const char *directory, const char *filename,
|
||||
const char *extension)
|
||||
{
|
||||
char *p = path;
|
||||
|
||||
if (!path || !size)
|
||||
{
|
||||
*_errno() = EINVAL;
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
if (drive && drive[0])
|
||||
{
|
||||
if (size <= 2)
|
||||
goto range;
|
||||
|
||||
*p++ = drive[0];
|
||||
*p++ = ':';
|
||||
size -= 2;
|
||||
}
|
||||
|
||||
if (directory && directory[0])
|
||||
{
|
||||
unsigned int len = strlen(directory);
|
||||
unsigned int needs_separator = directory[len - 1] != '/' && directory[len - 1] != '\\';
|
||||
unsigned int copylen = min(size - 1, len);
|
||||
|
||||
if (size < 2)
|
||||
goto range;
|
||||
|
||||
memmove(p, directory, copylen);
|
||||
|
||||
if (size <= len)
|
||||
goto range;
|
||||
|
||||
p += copylen;
|
||||
size -= copylen;
|
||||
|
||||
if (needs_separator)
|
||||
{
|
||||
if (size < 2)
|
||||
goto range;
|
||||
|
||||
*p++ = '\\';
|
||||
size -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (filename && filename[0])
|
||||
{
|
||||
unsigned int len = strlen(filename);
|
||||
unsigned int copylen = min(size - 1, len);
|
||||
|
||||
if (size < 2)
|
||||
goto range;
|
||||
|
||||
memmove(p, filename, copylen);
|
||||
|
||||
if (size <= len)
|
||||
goto range;
|
||||
|
||||
p += len;
|
||||
size -= len;
|
||||
}
|
||||
|
||||
if (extension && extension[0])
|
||||
{
|
||||
unsigned int len = strlen(extension);
|
||||
unsigned int needs_period = extension[0] != '.';
|
||||
unsigned int copylen;
|
||||
|
||||
if (size < 2)
|
||||
goto range;
|
||||
|
||||
if (needs_period)
|
||||
{
|
||||
*p++ = '.';
|
||||
size -= 1;
|
||||
}
|
||||
|
||||
copylen = min(size - 1, len);
|
||||
memcpy(p, extension, copylen);
|
||||
|
||||
if (size <= len)
|
||||
goto range;
|
||||
|
||||
p += copylen;
|
||||
}
|
||||
|
||||
*p = '\0';
|
||||
return 0;
|
||||
|
||||
range:
|
||||
path[0] = '\0';
|
||||
*_errno() = ERANGE;
|
||||
return ERANGE;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue