2 $Id: unix.c,v 1.5 2010-02-28 17:02:49 didg Exp $
3 Copyright (c) 2010 Frank Lahm <franklahm@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
18 * Netatalk utility functions
23 #endif /* HAVE_CONFIG_H */
30 #include <sys/types.h>
35 #include <atalk/adouble.h>
37 #include <atalk/afp.h>
38 #include <atalk/logger.h>
39 #include <atalk/volume.h>
40 #include <atalk/vfs.h>
41 #include <atalk/util.h>
42 #include <atalk/unix.h>
45 * @brief get cwd in static buffer
47 * @returns pointer to path or pointer to error messages on error
49 const char *getcwdpath(void)
51 static char cwd[MAXPATHLEN + 1];
54 if ((p = getcwd(cwd, MAXPATHLEN)) != NULL)
57 return strerror(errno);
61 * @brief symlink safe chdir replacement
63 * Only chdirs to dir if it doesn't contain symlinks.
65 * @returns 1 if a path element is a symlink, 0 otherwise, -1 on syserror
67 int lchdir(struct vol *vol, const char *dir)
69 char buf[MAXPATHLEN+1];
76 * chdir request | realpath result | ret
78 * =======================================
81 * /a/b/. | /c/d/e/f | 1
83 if (getcwd(buf, MAXPATHLEN) == NULL)
86 for (int i = 0; vol->v_path[i]; i++) {
87 if (buf[i] != vol->v_path[i]) {