www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2001/06/11/14:56:09

From: "Mark E." <snowball3 AT bigfoot DOT com>
To: djgpp-workers AT delorie DOT com
Date: Mon, 11 Jun 2001 14:55:41 -0400
MIME-Version: 1.0
Subject: confstr v3
Message-ID: <3B24DBED.8520.76BA38@localhost>
X-mailer: Pegasus Mail for Win32 (v3.12c)
Reply-To: djgpp-workers AT delorie DOT com

This version adds a static constructor to stash away the value of DJDIR at 
startup.

/* Copyright (C) 2001 DJ Delorie, see COPYING.DJ for details */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>

static char startup_djdir[FILENAME_MAX];

static void __attribute__((constructor))
init_confstr(void)
{
  char *djdir = getenv("DJDIR");
  if (djdir)
    strcpy(startup_djdir, djdir);
}

size_t
confstr(int name, char *buf, size_t len)
{
  size_t out_len = 0;

  switch (name)
  {
    case _CS_PATH:
    {
      if (startup_djdir)
      {
        out_len = snprintf(buf, len, "%s/bin", startup_djdir);
        /* snprintf excludes the null terminator from its return value,
           but confstr includes it.  */
        ++out_len;
      }
      break;
    }
    default:
    {
      errno = EINVAL;
    }
  }
  return out_len;
}


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019