tru64-unix-managers (formerly alpha-osf-managers) (1994-2012)
 help / color / mirror / Atom feed
From: winger () sewp ! nasa ! gov (Dan Winger)
To: tru64-unix-managers
Subject: fopen/fread broken under OSF/1 V3.0?
Date: Fri, 03 Feb 1995 21:45:53 +0000	[thread overview]
Message-ID: <96075317506375.tru64-unix-managers.marc@archive.invalid> (raw)


	I have an Alpha 3000 / Model 600 running OSF/1 V3.0.

I am trying to read the file "/var/adm/utmp" with a program I am
writing.  I am following all of the necessary rules, that I am aware
of, to compile and run this program.  The program works fine when
it is compiled and executed under Solaris 2.3 on a Sun SparcServer 10, 
but not here.

Running the broken program using "dbx":

# dbx
enter object file name (default is `a.out'): 
dbx version 3.11.6
Type 'help' for help.

main:  26  int i=0;
(dbx) run
readut: Error 0
DATE/TIME                       USER            INIT                    PID    STATUS                   HOST
----------------------------    ------------    ----------------        ------ --------------------     -------------------------
sizeof(struct utmp) = 156
About to read
signal Segmentation fault at   [memcpy:78 ,0x3ff8083b2e4]        Source not available
(dbx) where
>  0 memcpy(0x3ff80862a78, 0x3ffc0800678, 0x2, 0x9c, 0x3ff00000000) ["../../../../../src/usr/ccs/lib/libc/alpha/memcpy.s":78, 0x3ff8083b2e4]
   1 fread(0x140000188, 0x9c, 0x1, 0x0, 0x0) ["../../../../../src/usr/ccs/lib/libc/fread.c":154, 0x3ff80862b04]
   2 main() ["readut.c":54, 0x1200015e8]
(dbx) 

------------------------------------------------------------------------------

Here is the source code that I am running:

#include <stdio.h>
#include <utmp.h>
#include <time.h>
#include <errno.h>
#include <string.h>

/* @ timestamp */

char    *timestamp (time_t timeval)
{
struct tm       *tp ;
static char     buffer [64] ;

tp = localtime (&timeval) ;

/* Put the date into the format yyyy mmm dd */

strftime (buffer, sizeof(buffer), "%C", tp) ;
return buffer ;
}

main()
{
  FILE *fd;
  struct utmp *ut;
  int i=0;
  char *ut_type[10];
  size_t j,k;

  ut_type[0] = "Empty        ";
  ut_type[1] = "Run Level    ";
  ut_type[2] = "Boot Time    ";
  ut_type[3] = "Old Time     ";
  ut_type[4] = "New Time     ";
  ut_type[5] = "Init Process ";
  ut_type[6] = "Login Process";
  ut_type[7] = "User Process ";
  ut_type[8] = "Dead Process ";
  ut_type[9] = "Accounting   ";

  fd = fopen("/var/adm/utmp","r");
  perror("readut");
  ferror(fd);

  rewind(fd);

  printf("DATE/TIME                     USER            INIT			PID     STATUS                  HOST\n");
  printf("----------------------------  ------------    ----------------	------  --------------------    -------------------------\n");

  k = sizeof(struct utmp);
  printf("sizeof(struct utmp) = %d\n",k);

  printf("About to read\n");
  j=fread(ut,sizeof(struct utmp),1,fd);
  perror("readut");
  printf("After read j=%d\n",j);

  while(j>0)
    {
      printf("%s        ",timestamp(ut->ut_time));
      printf("%12s      ",ut->ut_user);
      printf("%16s      ",ut->ut_id);
      printf("%6d       ",ut->ut_pid);
      printf("%s        ",ut_type[ut->ut_type]);
      printf("%s\n",ut->ut_host);
      if(++i==24)
        {
          i=0;
          sleep(2);
          printf("\n");
          printf("DATE/TIME                     USER            INIT                    PID     STATUS                  HOST\n");
          printf("----------------------------  ------------    ----------------        ------  --------------------    -------------------------\n");
        }
      printf("About to read\n");
      j=fread(ut,sizeof(struct utmp),1,fd);
      perror("readut");
      printf("After read\n");
    }

  fclose(fd);
}

-----------------------------------------------------------------------

	It's a very simple, straight forward program.  Is this a bug in
the C compiler that I am using?  The C compiler is the one that came with the
operating system.  Any help would be appreciated.

Thank You.

Dan Winger  __   _     *      )     * NASA-Goddard Space Flight Center
SEWP BOWL (soop bol)   *   _ ( \\   * RMS Technologies Inc.
winger@sewp.nasa.gov   *  (_X__//_  * Code 251.9
301.286.7658           * (        ) * Bldg 18 Room 274
FAX 301.286.1619       *  \______/  * Greenbelt, MD  20771

                 reply	other threads:[~1995-02-03 21:45 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox