delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2001/06/07/12:19:53

From: "Mark E." <snowball3 AT bigfoot DOT com>
To: djgpp-workers AT delorie DOT com
Date: Thu, 7 Jun 2001 12:20:04 -0400
MIME-Version: 1.0
Subject: confstr v2
Message-ID: <3B1F7174.21905.7E6DAE@localhost>
X-mailer: Pegasus Mail for Win32 (v3.12c)
Reply-To: djgpp-workers AT delorie DOT com

This version fixes a missing path in the _CS_PATH case and an off-by-one 
error in the returned buffer length.

Eli, do you still believe the value of DJDIR at startup should be stashed 
away?

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

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

  switch (name)
  {
    case _CS_PATH:
    {
      char *djdir = getenv("DJDIR");
      if (djdir)
      {
        out_len = snprintf(buf, len, "%s/bin", 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