xref: /reactos/sdk/lib/crt/stdlib/makepath.c (revision d2aeaba5)
1 /*
2  * PROJECT:     ReactOS CRT library
3  * LICENSE:     See COPYING in the top level directory
4  * FILE:        lib/sdk/crt/stdlib/makepath.c
5  * PURPOSE:     Creates a path
6  * PROGRAMMERS: Wine team
7  *              Copyright 1996,1998 Marcus Meissner
8  *              Copyright 1996 Jukka Iivonen
9  *              Copyright 1997,2000 Uwe Bonnes
10  *              Copyright 2000 Jon Griffiths
11  *
12  */
13 
14 #include <precomp.h>
15 #include <stdlib.h>
16 #include <string.h>
17 
18 /*
19  * @implemented
20  */
21 void _makepath(char* path, const char* drive, const char* dir, const char* fname, const char* ext)
22 {
23     char *p = path;
24 
25     if ( !path )
26         return;
27 
28     if (drive && drive[0])
29     {
30         *p++ = drive[0];
31         *p++ = ':';
32     }
33     if (dir && dir[0])
34     {
35         size_t len = strlen(dir);
36         memmove(p, dir, len);
37         p += len;
38         if (p[-1] != '/' && p[-1] != '\\')
39             *p++ = '\\';
40     }
41     if (fname && fname[0])
42     {
43         size_t len = strlen(fname);
44         memmove(p, fname, len);
45         p += len;
46     }
47     if (ext && ext[0])
48     {
49         if (ext[0] != '.')
50             *p++ = '.';
51         strcpy(p, ext);
52     }
53     else
54         *p = '\0';
55 }
56