]>
git.ipfire.org Git - thirdparty/bash.git/blob - lib/sh/makepath.c
13aad3f0e8134aadefa91f2970646eb82b910c7c
1 /* makepath.c - glue PATH and DIR together into a full pathname. */
3 /* Copyright (C) 1987, 1989, 1991 Free Software Foundation, Inc.
5 This file is part of GNU Bash, the Bourne Again SHell.
7 Bash is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 Bash is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License along
18 with Bash; see the file COPYING. If not, write to the Free Software
19 Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
23 #if defined (HAVE_UNISTD_H)
25 # include <sys/types.h>
33 #include <tilde/tilde.h>
39 /* MAKE SURE THESE AGREE WITH ../../externs.h. */
42 # define MP_DOTILDE 0x01
43 # define MP_DOCWD 0x02
44 # define MP_RMDOT 0x04
47 extern char *get_working_directory
__P((char *));
49 /* Take PATH, an element from, e.g., $CDPATH, and DIR, a directory name,
50 and paste them together into PATH/DIR. Tilde expansion is performed on
51 PATH if (flags & MP_DOTILDE) is non-zero. If PATH is NULL or the empty
52 string, it is converted to the current directory. A full pathname is
53 used if (flags & MP_DOCWD) is non-zero, otherwise `./' is used. If
54 (flags & MP_RMDOT) is non-zero, any `./' is removed from the beginning
59 xpath = (char *)xmalloc (2); \
66 sh_makepath (path
, dir
, flags
)
67 const char *path
, *dir
;
71 char *ret
, *xpath
, *xdir
, *r
, *s
;
73 if (path
== 0 || *path
== '\0')
77 xpath
= get_working_directory ("sh_makepath");
80 ret
= get_string_value ("PWD");
82 xpath
= savestring (ret
);
87 pathlen
= strlen (xpath
);
94 xpath
= ((flags
& MP_DOTILDE
) && *path
== '~') ? bash_tilde_expand (path
) : (char *)path
;
95 pathlen
= strlen (xpath
);
99 dirlen
= strlen (xdir
);
100 if ((flags
& MP_RMDOT
) && dir
[0] == '.' && dir
[1] == '/')
106 r
= ret
= (char *)xmalloc (2 + dirlen
+ pathlen
);