ReactOS 0.4.16-dev-117-g38f21f9
makepath_s.c File Reference
#include <precomp.h>
#include <stdlib.h>
#include <string.h>
Include dependency graph for makepath_s.c:

Go to the source code of this file.

Functions

int CDECL _makepath_s (char *path, size_t size, const char *drive, const char *directory, const char *filename, const char *extension)
 

Function Documentation

◆ _makepath_s()

int CDECL _makepath_s ( char path,
size_t  size,
const char drive,
const char directory,
const char filename,
const char extension 
)

Definition at line 23 of file makepath_s.c.

26{
27 char *p = path;
28
29 if (!path || !size)
30 {
31 *_errno() = EINVAL;
32 return EINVAL;
33 }
34
35 if (drive && drive[0])
36 {
37 if (size <= 2)
38 goto range;
39
40 *p++ = drive[0];
41 *p++ = ':';
42 size -= 2;
43 }
44
45 if (directory && directory[0])
46 {
47 size_t len = strlen(directory);
48 unsigned int needs_separator = directory[len - 1] != '/' && directory[len - 1] != '\\';
49 size_t copylen = min(size - 1, len);
50
51 if (size < 2)
52 goto range;
53
54 memmove(p, directory, copylen);
55
56 if (size <= len)
57 goto range;
58
59 p += copylen;
60 size -= copylen;
61
62 if (needs_separator)
63 {
64 if (size < 2)
65 goto range;
66
67 *p++ = '\\';
68 size -= 1;
69 }
70 }
71
72 if (filename && filename[0])
73 {
74 size_t len = strlen(filename);
75 size_t copylen = min(size - 1, len);
76
77 if (size < 2)
78 goto range;
79
80 memmove(p, filename, copylen);
81
82 if (size <= len)
83 goto range;
84
85 p += len;
86 size -= len;
87 }
88
89 if (extension && extension[0])
90 {
91 size_t len = strlen(extension);
92 unsigned int needs_period = extension[0] != '.';
93 size_t copylen;
94
95 if (size < 2)
96 goto range;
97
98 if (needs_period)
99 {
100 *p++ = '.';
101 size -= 1;
102 }
103
104 copylen = min(size - 1, len);
105 memcpy(p, extension, copylen);
106
107 if (size <= len)
108 goto range;
109
110 p += copylen;
111 }
112
113 *p = '\0';
114 return 0;
115
116range:
117 path[0] = '\0';
118 *_errno() = ERANGE;
119 return ERANGE;
120}
#define EINVAL
Definition: acclib.h:90
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define ERANGE
Definition: acclib.h:92
GLsizeiptr size
Definition: glext.h:5919
GLenum GLint * range
Definition: glext.h:7539
GLfloat GLfloat p
Definition: glext.h:8902
GLenum GLsizei len
Definition: glext.h:6722
const char * filename
Definition: ioapi.h:137
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
#define min(a, b)
Definition: monoChain.cc:55
_CRTIMP int *__cdecl _errno(void)
Definition: errno.c:17