home-etc: configure.ac, doc/get_home_etc.3, doc/home_etc_expand_ti...
siefca
siefca at pld-linux.org
Thu May 18 01:41:28 CEST 2006
Author: siefca Date: Wed May 17 23:41:28 2006 GMT
Module: home-etc Tag: HEAD
---- Log message:
- documentation updated
- major fixes
- fixme tomorrow: sigsegv at realpath
---- Files affected:
home-etc:
configure.ac (1.10 -> 1.11)
home-etc/doc:
get_home_etc.3 (1.7 -> 1.8) , home_etc_expand_tilde.3 (1.3 -> 1.4)
home-etc/src:
core.c (1.21 -> 1.22) , core.h (1.11 -> 1.12) , home_etc.c (1.16 -> 1.17) , includes.h (1.3 -> 1.4) , realpath.c (1.2 -> 1.3)
---- Diffs:
================================================================
Index: home-etc/configure.ac
diff -u home-etc/configure.ac:1.10 home-etc/configure.ac:1.11
--- home-etc/configure.ac:1.10 Wed May 17 18:14:01 2006
+++ home-etc/configure.ac Thu May 18 01:41:23 2006
@@ -30,7 +30,7 @@
dnl Checks for header files.
AC_HEADER_STDC
-AC_CHECK_HEADERS([stdio.h stdlib.h string.h strings.h memory.h pwd.h sys/param.h sys/types.h unistd.h])
+AC_CHECK_HEADERS([stdio.h stdlib.h string.h strings.h memory.h pwd.h sys/param.h sys/types.h errno.h unistd.h])
dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
@@ -38,7 +38,7 @@
AC_TYPE_SIZE_T
dnl Checks for library functions.
-AC_CHECK_FUNCS([bzero endpwent getcwd setenv strrchr strchr memcpy memset])
+AC_CHECK_FUNCS([bzero endpwent getcwd setenv strrchr strchr memcpy memset perror])
AC_CONFIG_FILES([Makefile
home-etc.spec
================================================================
Index: home-etc/doc/get_home_etc.3
diff -u home-etc/doc/get_home_etc.3:1.7 home-etc/doc/get_home_etc.3:1.8
--- home-etc/doc/get_home_etc.3:1.7 Wed May 17 23:30:32 2006
+++ home-etc/doc/get_home_etc.3 Thu May 18 01:41:23 2006
@@ -28,7 +28,7 @@
.fi
.SH DESCRIPTION
The function \fBget_home_etc(3)\fP is used to obtain the directory name
-decided by user to store configuration files for the applications.
+chosen by user to store configuration files for the applications.
It makes the following things:
.LP
\- it checks whether the \fBHOME_ETC\fP environment variable is set
================================================================
Index: home-etc/doc/home_etc_expand_tilde.3
diff -u home-etc/doc/home_etc_expand_tilde.3:1.3 home-etc/doc/home_etc_expand_tilde.3:1.4
--- home-etc/doc/home_etc_expand_tilde.3:1.3 Wed May 17 23:30:32 2006
+++ home-etc/doc/home_etc_expand_tilde.3 Thu May 18 01:41:23 2006
@@ -21,16 +21,16 @@
.BI _HE_UNLIKE_TILDE;
.fi
.SH DESCRIPTION
-The function \fBhome_etc_expand_tilde(3)\fP is used to set leading
+The function \fBhome_etc_expand_tilde(3)\fP is used to set the leading
tilde & slash parsing, while processing pathnames by \fBhome_etc_path(3)\fP.
It takes one argument, which should be set to 0 to disable and to non-zero to
-enable parsing of a leading \fI~/\fP string found in path. When parsing
+enable parsing of the leading \fI~/\fP string found in path. When parsing
is enabled, the path is expanded by replacing \fI~/\fP by user's home directory
pathname while invoking internal routines. Additionally, the \fI~\fP character
is also translated into user's home directory name, but only if the whole parsed
path contains only that one character.
-The way to obtain user's home directory depends on method choosen while
+The way to obtain user's home directory depends on method chosen while
invoking \fBhome_etc_path(3)\fP. The \fIuse_env\fP is a swich which
determines the method to obtain user's home directory. If it's set
to 1 home directory is obtained using \fIHOME\fP environment variable.
================================================================
Index: home-etc/src/core.c
diff -u home-etc/src/core.c:1.21 home-etc/src/core.c:1.22
--- home-etc/src/core.c:1.21 Wed May 17 23:30:32 2006
+++ home-etc/src/core.c Thu May 18 01:41:23 2006
@@ -7,11 +7,11 @@
*
*/
-#include <stdio.h>
-
#include "includes.h"
#include "core.h"
+extern int errno;
+
/*********************************************************************/
const char *compare_paths(const char *a, const char *b)
@@ -64,7 +64,7 @@
/*********************************************************************/
-const char *canonize_path(const char *path, char use_env, char expand_tilde)
+char *canonize_path(const char *path, char use_env, char expand_tilde)
{
char trailslash = 0;
int counter = 256;
================================================================
Index: home-etc/src/core.h
diff -u home-etc/src/core.h:1.11 home-etc/src/core.h:1.12
--- home-etc/src/core.h:1.11 Wed May 17 03:50:04 2006
+++ home-etc/src/core.h Thu May 18 01:41:23 2006
@@ -16,12 +16,29 @@
#define ENV_VAR "HOME_ETC"
#define HELPER_FILENAME ".home_etc"
+extern int errno;
+
const char *obtain_home_dir(char use_env);
const char *get_home_etc_core(char use_env);
const char *home_etc_path_core(const char *path, char use_env);
-const char *canonize_path(const char *path, char use_env, char expand_tilde);
+char *canonize_path(const char *path, char use_env, char expand_tilde);
const char *compare_paths(const char *a, const char *b);
+
+inline static int isdir(const char *path)
+{
+ char prev[MAXPATHLEN];
+
+ prev[MAXPATHLEN-1] = '\0';
+ if (! getcwd(prev, sizeof(prev)))
+ return 0;
+
+ if (chdir(path) == -1 && errno == ENOTDIR)
+ return 0;
+
+ chdir(prev);
+ return 1;
+}
#endif
================================================================
Index: home-etc/src/home_etc.c
diff -u home-etc/src/home_etc.c:1.16 home-etc/src/home_etc.c:1.17
--- home-etc/src/home_etc.c:1.16 Wed May 17 18:14:01 2006
+++ home-etc/src/home_etc.c Thu May 18 01:41:23 2006
@@ -119,12 +119,12 @@
/* absolutize home directory name */
strncpy(home_dir, p, sizeof(home_dir)-1);
- p = canonize_path(home_dir, use_env, 0);
+ p = (const char *) canonize_path(home_dir, use_env, 0);
if (p == NULL || *p == '\0')
return NULL;
/* absolutize given pathname */
- p = canonize_path(path, use_env, h_etc_expand_tilde);
+ p = (const char *) canonize_path(path, use_env, h_etc_expand_tilde);
if (p == NULL || *p == '\0')
return NULL;
@@ -241,11 +241,45 @@
}
/****************************************************************/
-/* canonize pathname as it is possible */
+/* canonize as many pathname's parts as it is possible */
const char *path_canonize(const char *path, char use_env)
{
- return canonize_path(path, use_env, h_etc_expand_tilde);
+ size_t s = 0;
+ const char *r;
+ char *p = NULL;
+ char *q = NULL;
+ char *b = NULL;
+
+ p = canonize_path(path, use_env, h_etc_expand_tilde);
+ if (p == NULL)
+ return NULL;
+
+ /* remove doubled slashes */
+ q = b = p;
+ while (*q != '\0')
+ {
+ if (*q == '/' && *(q+1) == '/' && (s=1))
+ while (*(q+1) == '/') q++;
+ else
+ {
+ if (s)
+ {
+ *b = *q;
+ }
+ }
+ q++; b++;
+ }
+ if (q > b)
+ *b = '\0';
+
+ /* check whether the trailing slash should be removed */
+ s = strlen(p);
+ if (s > 0 && *(p+s-1) == '/' && !isdir(p))
+ *(p+s-1) = '\0';
+
+ r = (const char *) p;
+ return r;
}
/*
================================================================
Index: home-etc/src/includes.h
diff -u home-etc/src/includes.h:1.3 home-etc/src/includes.h:1.4
--- home-etc/src/includes.h:1.3 Wed May 17 03:50:04 2006
+++ home-etc/src/includes.h Thu May 18 01:41:23 2006
@@ -76,6 +76,10 @@
# include <pwd.h>
#endif
+#if HAVE_ERRNO_H
+# include <errno.h>
+#endif
+
#ifndef MAXPATHLEN
# define MAXPATHLEN 4096
#endif
================================================================
Index: home-etc/src/realpath.c
diff -u home-etc/src/realpath.c:1.2 home-etc/src/realpath.c:1.3
--- home-etc/src/realpath.c:1.2 Wed May 17 23:30:32 2006
+++ home-etc/src/realpath.c Thu May 18 01:41:23 2006
@@ -38,7 +38,10 @@
if (r == NULL || *r == '\0')
{
er = errno;
- perror("realpath");
+ if (*r == '\0')
+ fprintf(stderr, "realpath: got an empty result\n");
+ else
+ perror("realpath");
fprintf(stdout, "-\n");
}
else
================================================================
---- CVS-web:
http://cvs.pld-linux.org/home-etc/configure.ac?r1=1.10&r2=1.11&f=u
http://cvs.pld-linux.org/home-etc/doc/get_home_etc.3?r1=1.7&r2=1.8&f=u
http://cvs.pld-linux.org/home-etc/doc/home_etc_expand_tilde.3?r1=1.3&r2=1.4&f=u
http://cvs.pld-linux.org/home-etc/src/core.c?r1=1.21&r2=1.22&f=u
http://cvs.pld-linux.org/home-etc/src/core.h?r1=1.11&r2=1.12&f=u
http://cvs.pld-linux.org/home-etc/src/home_etc.c?r1=1.16&r2=1.17&f=u
http://cvs.pld-linux.org/home-etc/src/includes.h?r1=1.3&r2=1.4&f=u
http://cvs.pld-linux.org/home-etc/src/realpath.c?r1=1.2&r2=1.3&f=u
More information about the pld-cvs-commit
mailing list