chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] Return value of `system'


From: Kon Lovett
Subject: Re: [Chicken-users] Return value of `system'
Date: Wed, 14 Mar 2007 15:49:33 -0700

On Mar 14, 2007, at 2:55 PM, Zbigniew wrote:

Exit values should be distinguishable from signals (and even from
signals+core dumps).  Either use the C macros, or assume bits 15-8 are
the exit return code, bit 7 is the core dump, and bits 6-0 are the
signal number (with 127 being shell exec failure).  It's the same as
in Perl unless Chicken does something weird with the return from
system; granted I haven't looked at the code.  Hopefully Chicken's
(system) returns the value of system(), not errno.  system() never
sets errno to my knowledge.

From "runtime.c":

C_regparm C_word C_fcall C_execute_shell_command(C_word string)
{
  int n = C_header_size(string);
  char *buf = buffer;

  if(n >= STRING_BUFFER_SIZE) {
    if((buf = (char *)C_malloc(n + 1)) == NULL)
      barf(C_OUT_OF_MEMORY_ERROR, "system");
  }

  C_memcpy(buf, ((C_SCHEME_BLOCK *)string)->data, n);
  buf[ n ] = '\0';

  n = C_system(buf);

  if(buf != buffer) C_free(buf);

  if(n == -1)
    return C_fix(errno);

#ifdef C_NONUNIX
  return C_fix(n);
#else
return C_fix(WIFEXITED(n) ? WEXITSTATUS(n) : (WIFSIGNALED(n) ? WTERMSIG(n) : WSTOPSIG(n)));
#endif
}

I don't always talk thru my hat ;-)

Best Wishes,
Kon


On 3/14/07, Kon Lovett <address@hidden> wrote:
IMHO this means the return value is almost useless w/o some hoops;
i.e. if 'errno' == the return value the return value is error value,
but differentiating an exit-status from a signal-code is probably
impossible.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]