DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: T i

⟦b951ff72e⟧ TextFile

    Length: 11061 (0x2b35)
    Types: TextFile
    Names: »ioutil.c.~1~«

Derivation

└─⟦a05ed705a⟧ Bits:30007078 DKUUG GNU 2/12/89
    └─⟦4ef0278ca⟧ »./binutils.tar.Z« 
        └─⟦3761b9c35⟧ 
            └─⟦this⟧ »binutils/hp-bin/ioutil.c.~1~« 

TextFile

/* I/O Utilities
   Copyright (C) 1988 Free Software Foundation, Inc.

		       NO WARRANTY

  BECAUSE THIS PROGRAM IS LICENSED FREE OF CHARGE, WE PROVIDE ABSOLUTELY
NO WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE LAW.  EXCEPT
WHEN OTHERWISE STATED IN WRITING, FREE SOFTWARE FOUNDATION, INC,
RICHARD M. STALLMAN AND/OR OTHER PARTIES PROVIDE THIS PROGRAM "AS IS"
WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY
AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE PROGRAM PROVE
DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR
CORRECTION.

 IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL RICHARD M.
STALLMAN, THE FREE SOFTWARE FOUNDATION, INC., AND/OR ANY OTHER PARTY
WHO MAY MODIFY AND REDISTRIBUTE THIS PROGRAM AS PERMITTED BELOW, BE
LIABLE TO YOU FOR DAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR
OTHER SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR
DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR
A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS) THIS
PROGRAM, EVEN IF YOU HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY.

		GENERAL PUBLIC LICENSE TO COPY

  1. You may copy and distribute verbatim copies of this source file
as you receive it, in any medium, provided that you conspicuously
and appropriately publish on each copy a valid copyright notice
"Copyright (C) 1988 Free Software Foundation, Inc.", and include
following the copyright notice a verbatim copy of the above disclaimer
of warranty and of this License.

  2. You may modify your copy or copies of this source file or
any portion of it, and copy and distribute such modifications under
the terms of Paragraph 1 above, provided that you also do the following:

    a) cause the modified files to carry prominent notices stating
    that you changed the files and the date of any change; and

    b) cause the whole of any work that you distribute or publish,
    that in whole or in part contains or is a derivative of this
    program or any part thereof, to be licensed at no charge to all
    third parties on terms identical to those contained in this
    License Agreement (except that you may choose to grant more extensive
    warranty protection to some or all third parties, at your option).

    c) You may charge a distribution fee for the physical act of
    transferring a copy, and you may at your option offer warranty
    protection in exchange for a fee.

Mere aggregation of another unrelated program with this program (or its
derivative) on a volume of a storage or distribution medium does not bring
the other program under the scope of these terms.

  3. You may copy and distribute this program (or a portion or derivative
of it, under Paragraph 2) in object code or executable form under the terms
of Paragraphs 1 and 2 above provided that you also do one of the following:

    a) accompany it with the complete corresponding machine-readable
    source code, which must be distributed under the terms of
    Paragraphs 1 and 2 above; or,

    b) accompany it with a written offer, valid for at least three
    years, to give any third party free (except for a nominal
    shipping charge) a complete machine-readable copy of the
    corresponding source code, to be distributed under the terms of
    Paragraphs 1 and 2 above; or,

    c) accompany it with the information you received as to where the
    corresponding source code may be obtained.  (This alternative is
    allowed only for noncommercial distribution and only if you
    received the program in object code or executable form alone.)

For an executable file, complete source code means all the source code for
all modules it contains; but, as a special exception, it need not include
source code for modules which are standard libraries that accompany the
operating system on which the executable file runs.

  4. You may not copy, sublicense, distribute or transfer this program
except as expressly provided under this License Agreement.  Any attempt
otherwise to copy, sublicense, distribute or transfer this program is void and
your rights to use the program under this License agreement shall be
automatically terminated.  However, parties who have received computer
software programs from you with this License Agreement will not have
their licenses terminated so long as such parties remain in full compliance.

  5. If you wish to incorporate parts of this program into other free
programs whose distribution conditions are different, write to the Free
Software Foundation at 675 Mass Ave, Cambridge, MA 02139.  We have not yet
worked out a simple rule that can be stated here, but we will often permit
this.  We will be guided by the two goals of preserving the free status of
all derivatives of our free software and of promoting the sharing and reuse of
software.

 In other words, you are welcome to use, share and improve this program.
 You are forbidden to forbid anyone else to use, share and improve
 what you give them.   Help stamp out software-hoarding!  */
\f


#include <stdio.h>
#include <varargs.h>
#include <sys/file.h>
#include <string.h>
#define index(s, c) strchr (s, c)
#include <errno.h>
#include <setjmp.h>
#include "ioutil.h"

char *iou_program_name;

void
iou_set_program_name (argv)
     char *argv [];
{
  register char *start;
  register char *slash;

  start = (argv [0]);
  while (1)
    {
      slash = (index (start, '/'));
      if (slash == NULL) break;
      start = (slash + 1);
    }
  iou_program_name = start;
  return;
}
\f


struct abort_list
  {
    struct abort_list *next;
    void (* handler) ();
    jmp_buf catch_point;
  };
typedef struct abort_list *abort_list;

static abort_list abort_handlers = NULL;

void
iou_abort ()
{
  register abort_list handlers;

  handlers = abort_handlers;
  if (handlers == NULL) abort ();
  longjmp ((handlers -> catch_point), 1); /*NOTREACHED*/
}

void
iou_abort_handler_bind (thunk, handler)
     void (* thunk) ();
     void (* handler) ();
{
  register abort_list handlers;
  register int setjmp_result;

  handlers = ((abort_list) (iou_malloc (sizeof (struct abort_list))));
  (handlers -> next) = abort_handlers;
  (handlers -> handler) = handler;
  abort_handlers = handlers;
  setjmp_result = (setjmp (handlers -> catch_point));
  switch (setjmp_result)
    {
    case 0:
      (* thunk) ();
      if (handlers != abort_handlers)
	iou_fatal_error ("iou_abort_handler_bind: sync error");
      abort_handlers = (handlers -> next);
      iou_free (handlers);
      return;

    case 1:
      {
	register abort_list handlers;
	register void (* handler) ();

	handlers = abort_handlers;
	handler = (handlers -> handler);
	abort_handlers = (handlers -> next);
	iou_free (handlers);
	(* handler) ();
	return;
      }

    default:
      iou_fatal_error ("Illegal setjmp value: %d", setjmp_result);
      /*NOTREACHED*/
    }
}
\f


#ifndef hpux
#ifdef bsd

static void
vfprintf (stream, format, args)
     FILE *stream;
     char *format;
     char *args;
{
  _doprnt (format, args, stderr);
  return;
}

#else
#include "error: no definition for `vfprintf' procedure"
#endif
#endif

#define WARN()								\
{									\
  va_list args;								\
  char *format;								\
									\
  fprintf (stderr, "%s: ", iou_program_name);				\
  va_start (args);							\
  format = (va_arg (args, char *));					\
  vfprintf (stderr, format, args);					\
  va_end (args);							\
  putc ('\n', stderr);							\
}

/*VARARGS0*/ void
iou_warning (va_alist)
     va_dcl
{
  WARN();
  return;
}

/*VARARGS0*/ void
iou_error (va_alist)
     va_dcl
{
  WARN();
  iou_abort (); /*NOTREACHED*/
}

/*VARARGS0*/ void
iou_fatal_error (va_alist)
     va_dcl
{
  WARN();
  abort (); /*NOTREACHED*/
}
\f


void
iou_call_warning (name)
     char *name;
{
  extern int sys_nerr;
  extern char *sys_errlist [];

  if (errno < sys_nerr)
    iou_warning ("%s during system call: %s", (sys_errlist [errno]), name);
  else
    iou_warning ("error code %d during system call: %s", errno, name);
  return;
}

void
iou_call_error (name)
     char *name;
{
  iou_call_warning (name);
  iou_abort (); /*NOTREACHED*/
}

void
iou_stat (path, buf)
     char *path;
     struct stat *buf;
{
  extern int stat ();
  register int result;

  while (1)
    {
      result = (stat (path, buf));
      if (result == 0) break;
      if (errno != EINTR) iou_call_error ("stat");
    }
  return;
}

void
iou_unlink (path)
     char *path;
{
  extern int unlink ();

  if ((unlink (path)) != 0)
    iou_call_error ("unlink");
  return;
}
\f


int
iou_open (path, oflag, mode)
     char *path;
     int oflag;
     int mode;
{
  extern int open ();
  register int result;

  while (1)
    {
      result = (open (path, oflag, mode));
      if (result >= 0) break;
      if (errno != EINTR) iou_call_error ("open");
    }
  return (result);
}

void
iou_close (descriptor)
     int descriptor;
{
  if ((close (descriptor)) != 0)
    iou_call_error ("close");
  return;
}

long
iou_lseek (descriptor, offset, whence)
     int descriptor;
     long offset;
     int whence;
{
  extern long lseek ();
  register long result;

  while (1)
    {
      result = (lseek (descriptor, offset, whence));
      if (result >= 0) break;
      if (errno != EINTR) iou_call_error ("lseek");
    }
  return (result);
}
\f


int
iou_read (input_file, buffer, length)
     int input_file;
     register char *buffer;
     int length;
{
  extern int read ();
  register int bytes_remaining;
  register int result;

  bytes_remaining = length;
  while (bytes_remaining > 0)
    {
      result = (read (input_file, buffer, bytes_remaining));
      if (result == 0) return (length - bytes_remaining);
      if (result > 0)
	{
	  buffer += result;
	  bytes_remaining -= result;
	  continue;
	}
      if (errno != EINTR) iou_call_error ("read");
    }
  return (length);
}

void
iou_write (output_file, buffer, length)
     int output_file;
     register char *buffer;
     register int length;
{
  extern int write ();
  register int bytes_remaining;
  register int result;

  bytes_remaining = length;
  while (bytes_remaining > 0)
    {
      result = (write (output_file, buffer, bytes_remaining));
      if (result >= 0)
	{
	  buffer += result;
	  bytes_remaining -= result;
	  continue;
	}
      if (errno != EINTR) iou_call_error ("write");
    }
  return;
}
\f


char *
iou_malloc (length)
     unsigned length;
{
  extern char *malloc ();
  register char *result;

  result = (malloc (length));
  if (result == NULL) iou_error ("virtual memory exhausted");
  return (result);
}

char *
iou_realloc (pointer, length)
     char *pointer;
     unsigned length;
{
  extern char *realloc ();
  register char *result;

  result = (realloc (pointer, length));
  if (result == NULL) iou_error ("virtual memory exhausted");
  return (result);
}