Skip to content
Extraits de code Groupes Projets
Valider 753b1450 rédigé par Etienne BRATEAU's avatar Etienne BRATEAU
Parcourir les fichiers

reintent utils/misc

parent e7a0da57
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -11,22 +11,22 @@
void misc_getioerrmsg(char *s, long i)
{
sprintf(s, "misc_getioerrmsg Error number %ld", i);
sprintf(s, "misc_getioerrmsg Error number %ld", i);
}
#if defined __FreeBSD__ || defined __bsdi__
char *cuserid(char *s)
{
char *sp;
static char sbuf[L_cuserid + 1];
char *sp;
static char sbuf[L_cuserid + 1];
if ((sp = getenv("USER")) == NULL) {
if (s != NULL)
s[0] = '\0';
return NULL;
}
return strncpy(s != NULL ? s : sbuf, sp, L_cuserid);
if ((sp = getenv("USER")) == NULL) {
if (s != NULL)
s[0] = '\0';
return NULL;
}
return strncpy(s != NULL ? s : sbuf, sp, L_cuserid);
}
#endif
......@@ -40,33 +40,33 @@ char *cuserid(char *s)
*/
char *tilde_expand(char *s)
{
char *name;
char *ret = NULL;
size_t len = 0;
struct passwd *pw;
char *name;
char *ret = NULL;
size_t len = 0;
struct passwd *pw;
if (*s == '~') {
if (strlen(s) > 1)
len = strcspn(s+1, "/");
if (len > 0) {
name = (char *) Malloc(len + 1);
strncpy(name, s+1, len);
name[len] = '\0';
pw = getpwnam(name);
Free(name);
} else {
pw = getpwuid( geteuid() );
}
if (pw != NULL) {
ret = (char *) Malloc(strlen(pw->pw_dir) + strlen(s) - len);
strcpy(ret,pw->pw_dir);
if (strlen(s) > len + 1)
strcat(ret, s + len + 1);
}
}
if (ret == NULL)
ret = strdup(s);
return ret;
if (*s == '~') {
if (strlen(s) > 1)
len = strcspn(s+1, "/");
if (len > 0) {
name = (char *) Malloc(len + 1);
strncpy(name, s+1, len);
name[len] = '\0';
pw = getpwnam(name);
Free(name);
} else {
pw = getpwuid( geteuid() );
}
if (pw != NULL) {
ret = (char *) Malloc(strlen(pw->pw_dir) + strlen(s) - len);
strcpy(ret,pw->pw_dir);
if (strlen(s) > len + 1)
strcat(ret, s + len + 1);
}
}
if (ret == NULL)
ret = strdup(s);
return ret;
}
#else
......@@ -76,19 +76,19 @@ struct passwd *pw;
*/
char *tilde_expand(char *s)
{
char *hp;
char *ret = NULL;
char *hp;
char *ret = NULL;
if (*s == '~' && (hp = getenv("HOME")) != NULL) {
if ((ret = (char *) Malloc(strlen(hp) + strlen(s))) != NULL) {
strcpy(ret, hp);
if (strlen(s) > 1)
strcat(ret, s + 1);
}
}
if (ret == NULL)
ret = strdup(s);
return ret;
if (*s == '~' && (hp = getenv("HOME")) != NULL) {
if ((ret = (char *) Malloc(strlen(hp) + strlen(s))) != NULL) {
strcpy(ret, hp);
if (strlen(s) > 1)
strcat(ret, s + 1);
}
}
if (ret == NULL)
ret = strdup(s);
return ret;
}
#endif
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter