mirror of
https://github.com/lcn2/calc.git
synced 2025-08-16 01:03:29 +03:00
Release calc version 2.11.0t9.4.2
This commit is contained in:
49
lib_calc.c
49
lib_calc.c
@@ -34,6 +34,11 @@
|
||||
#include "symbol.h"
|
||||
#include "func.h"
|
||||
|
||||
#include "have_strdup.h"
|
||||
#if !defined(HAVE_STRDUP)
|
||||
# define strdup(x) calc_strdup((CONST char *)(x))
|
||||
#endif /* HAVE_STRDUP */
|
||||
|
||||
#include "have_unistd.h"
|
||||
#if defined(HAVE_UNISTD_H)
|
||||
#include <unistd.h>
|
||||
@@ -339,7 +344,7 @@ initenv(void)
|
||||
|
||||
/* determine the $HOME value */
|
||||
c = getenv(HOME);
|
||||
home = ((no_env || c == NULL) ? NULL : strdup(c));
|
||||
home = ((no_env || c == NULL) ? NULL : strdup(c));
|
||||
if (home == NULL || home[0] == '\0') {
|
||||
ent = (struct passwd *)getpwuid(geteuid());
|
||||
if (ent == NULL) {
|
||||
@@ -431,3 +436,45 @@ run_state_name(run state)
|
||||
}
|
||||
return "RUN_invalid";
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* calc_strdup - calc interface to provide or simulate strdup()
|
||||
*/
|
||||
char *
|
||||
calc_strdup(CONST char *s1)
|
||||
{
|
||||
#if defined(HAVE_STRDUP)
|
||||
|
||||
return strdup(s1);
|
||||
|
||||
#else /* HAVE_STRDUP */
|
||||
|
||||
char *ret; /* return string */
|
||||
|
||||
/*
|
||||
* firewall
|
||||
*/
|
||||
if (s1 == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* allocate duplicate storage
|
||||
*/
|
||||
ret = (char *)malloc(sizeof(char) * (strlen(s1)+1));
|
||||
|
||||
/*
|
||||
* if we have storage, duplicate the string
|
||||
*/
|
||||
if (ret != NULL) {
|
||||
strcpy(ret, s1);
|
||||
}
|
||||
|
||||
/*
|
||||
* return the new string, or NULL if malloc failed
|
||||
*/
|
||||
return ret;
|
||||
|
||||
#endif /* HAVE_STRDUP */
|
||||
}
|
||||
|
Reference in New Issue
Block a user