1 /***********************************************************************
2 * *
3 * This software is part of the ast package *
4 * Copyright (c) 1985-2011 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Eclipse Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
8 * *
9 * A copy of the License is available at *
10 * http://www.eclipse.org/org/documents/epl-v10.html *
11 * (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12 * *
13 * Information and Software Systems Research *
14 * AT&T Research *
15 * Florham Park NJ *
16 * *
17 * Glenn Fowler <gsf@research.att.com> *
18 * David Korn <dgk@research.att.com> *
19 * Phong Vo <kpv@research.att.com> *
20 * *
21 ***********************************************************************/
22 #pragma prototyped
23 /*
24 * Glenn Fowler
25 * AT&T Bell Laboratories
26 *
27 * single dir support for pathaccess()
28 */
29
30 #define _AST_API_H 1
31
32 #include <ast.h>
33
34 /*
35 * building 3d flirts with the dark side
36 */
37
38 #if _BLD_3d
39
40 #undef pathcat
41 #define pathcat_20100601 _3d_pathcat
42
43 #else
44
45 char*
pathcat(char * path,const char * dirs,int sep,const char * a,const char * b)46 pathcat(char* path, const char* dirs, int sep, const char* a, const char* b)
47 {
48 return pathcat_20100601(dirs, sep, a, b, path, PATH_MAX);
49 }
50
51 #endif
52
53 #undef _AST_API
54
55 #include <ast_api.h>
56
57 char*
pathcat_20100601(register const char * dirs,int sep,const char * a,register const char * b,char * path,size_t size)58 pathcat_20100601(register const char* dirs, int sep, const char* a, register const char* b, char* path, size_t size)
59 {
60 register char* s;
61 register char* e;
62
63 s = path;
64 e = path + size;
65 while (*dirs && *dirs != sep)
66 {
67 if (s >= e)
68 return 0;
69 *s++ = *dirs++;
70 }
71 if (s != path)
72 {
73 if (s >= e)
74 return 0;
75 *s++ = '/';
76 }
77 if (a)
78 {
79 while (*s = *a++)
80 if (++s >= e)
81 return 0;
82 if (b)
83 {
84 if (s >= e)
85 return 0;
86 *s++ = '/';
87 }
88 }
89 else if (!b)
90 b = ".";
91 if (b)
92 do
93 {
94 if (s >= e)
95 return 0;
96 } while (*s++ = *b++);
97 return *dirs ? (char*)++dirs : 0;
98 }
99