Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Postfix/src/util/   (Postfix Mailserver Version 3.11©)  Datei vom 15.6.2005 mit Größe 3 kB image not shown  

Quelle  environ.c

  Sprache: C
 

 /*
  * From: TCP Wrapper.
  * 
  * Many systems have putenv() but no setenv(). Other systems have setenv() but
  * no putenv() (MIPS). Still other systems have neither (NeXT). This is a
  * re-implementation that hopefully ends all problems.
  * 
  * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
  */

#include "sys_defs.h"

#ifdef MISSING_SETENV_PUTENV

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

extern char **environ;

static int addenv(char *);  /* append entry to environment */
static int allocated = 0;  /* environ is, or is not, allocated */

#define DO_CLOBBER      1

/* namelength - determine length of name in "name=whatever" */

static ssize_t namelength(const char *name)
{
    char   *equal;

    equal = strchr(name, '=');
    return ((equal == 0) ? strlen(name) : (equal - name));
}

/* findenv - given name, locate name=value */

static char **findenv(const char *name, ssize_t len)
{
    char  **envp;

    for (envp = environ; envp && *envp; envp++)
 if (strncmp(name, *envp, len) == 0 && (*envp)[len] == '=')
     return (envp);
    return (0);
}

#if 0

/* getenv - given name, locate value */

char   *getenv(const char *name)
{
    ssize_t len = namelength(name);
    char  **envp = findenv(name, len);

    return (envp ? *envp + len + 1 : 0);
}

/* putenv - update or append environment (name,value) pair */

int     putenv(const char *nameval)
{
    char   *equal = strchr(nameval, '=');
    char   *value = (equal ? equal : "");

    return (setenv(nameval, value, DO_CLOBBER));
}

/* unsetenv - remove variable from environment */

void    unsetenv(const char *name)
{
    char  **envp;

    while ((envp = findenv(name, namelength(name))) != 0)
 while (envp[0] = envp[1])
     envp++;
}

#endif

/* setenv - update or append environment (name,value) pair */

int     setenv(const char *name, const char *value, int clobber)
{
    char   *destination;
    char  **envp;
    ssize_t l_name;   /* length of name part */
    unsigned int l_nameval;  /* length of name=value */

    /* Permit name= and =value. */

    l_name = namelength(name);
    envp = findenv(name, l_name);
    if (envp != 0 && clobber == 0)
 return (0);
    if (*value == '=')
 value++;
    l_nameval = l_name + strlen(value) + 1;

    /*
     * Use available memory if the old value is long enough. Never free an
     * old name=value entry because it may not be allocated.
     */


    destination = (envp != 0 && strlen(*envp) >= l_nameval) ?
 *envp : malloc(l_nameval + 1);
    if (destination == 0)
 return (-1);
    strncpy(destination, name, l_name);
    destination[l_name] = '=';
    strcpy(destination + l_name + 1, value);
    return ((envp == 0) ? addenv(destination) : (*envp = destination, 0));
}

/* cmalloc - malloc and copy block of memory */

static char *cmalloc(ssize_t new_len, char *old, ssize_t old_len)
{
    char   *new = malloc(new_len);

    if (new != 0)
 memcpy(new, old, old_len);
    return (new);
}

/* addenv - append environment entry */

static int addenv(char *nameval)
{
    char  **envp;
    ssize_t n_used;   /* number of environment entries */
    ssize_t l_used;   /* bytes used excl. terminator */
    ssize_t l_need;   /* bytes needed incl. terminator */

    for (envp = environ; envp && *envp; envp++)
  /* void */ ;
    n_used = envp - environ;
    l_used = n_used * sizeof(*envp);
    l_need = l_used + 2 * sizeof(*envp);

    envp = allocated ?
 (char **) realloc((char *) environ, l_need) :
 (char **) cmalloc(l_need, (char *) environ, l_used);
    if (envp == 0) {
 return (-1);
    } else {
 allocated = 1;
 environ = envp;
 environ[n_used++] = nameval;  /* add new entry */
 environ[n_used] = 0;   /* terminate list */
 return (0);
    }
}

#endif

Messung V0.5 in Prozent
C=71 H=96 G=84

¤ Dauer der Verarbeitung: 0.14 Sekunden  (vorverarbeitet am  2026-08-09) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.