File: makepath.c

package info (click to toggle)
icmake 7.21.01-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,856 kB
  • ctags: 1,498
  • sloc: ansic: 7,791; makefile: 3,879; sh: 320; cpp: 83
file content (55 lines) | stat: -rw-r--r-- 1,326 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
    makepath.c pwp 93 07 14
    replacement function _makepath
    for NON-MSDOS systems ONLY

    Arguments:
        path:   buffer to contain the combined name; length _MAX_PATH
                this is NOT checked

        drive:  pointer to drive specifier; ignored
        dir:    directory string, can be NULL or empty ("");
                if not-empty, may have a trailing DIRSEP character
        fname:  basename string, can be NULL or empty ("")
        ext:    extension string, can be NULL or empty ("");
                if not empty, can have optional leading dot

*/

#include <stdio.h>
#include <string.h>
#include "icm.h"
#include "icrssdef.h"

static char
    dot[] = ".";

void _makepath(char * path,
    const char * drive, const char * dir, const char * fname, const char * ext)
{
    path[0] = '\x0';                        /*  prepare for strcats */

    if (dir && dir[0])
    {
        strcat(path, dir);

        if (dir[strlen(dir) - 1] != DIRSEP)
        {
            size_t l;

            path[l = strlen(path)] = DIRSEP;
            path[++l] = '\x0';              /*  make it an asciiz   */
        }
    }

    if (fname && fname[0])
        strcat(path, fname);

    if (ext && ext[0])
    {
        if (ext[0] != dot[0])
            strcat(path, dot);

        strcat(path, ext);
    }
}