This source file includes following definitions.
- concatenated_filename
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #include <config.h>
20
21
22 #include "concat-filename.h"
23
24 #include <errno.h>
25 #include <stdlib.h>
26 #include <string.h>
27
28 #include "filename.h"
29
30
31
32
33
34
35 char *
36 concatenated_filename (const char *directory, const char *filename,
37 const char *suffix)
38 {
39 char *result;
40 char *p;
41
42 if (strcmp (directory, ".") == 0)
43 {
44
45 result = (char *) malloc (strlen (filename)
46 + (suffix != NULL ? strlen (suffix) : 0)
47 + 1);
48 if (result == NULL)
49 return NULL;
50 p = result;
51 }
52 else
53 {
54 size_t directory_len = strlen (directory);
55 int need_slash =
56 (directory_len > FILE_SYSTEM_PREFIX_LEN (directory)
57 && !ISSLASH (directory[directory_len - 1]));
58 result = (char *) malloc (directory_len + need_slash
59 + strlen (filename)
60 + (suffix != NULL ? strlen (suffix) : 0)
61 + 1);
62 if (result == NULL)
63 return NULL;
64 memcpy (result, directory, directory_len);
65 p = result + directory_len;
66 if (need_slash)
67 *p++ = '/';
68 }
69 p = stpcpy (p, filename);
70 if (suffix != NULL)
71 stpcpy (p, suffix);
72 return result;
73 }