home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.questions
- Path: sparky!uunet!wupost!cs.uiuc.edu!vela!shiva
- From: shiva@vela.acs.oakland.edu (SHIVAKUMAR C. BETTADAPURA)
- Subject: File pointer misaligned if opened in append mode.
- Message-ID: <1992Nov19.224117.8860@vela.acs.oakland.edu>
- Organization: Oakland University, Rochester MI.
- Date: Thu, 19 Nov 1992 22:41:17 GMT
- Lines: 50
-
- I work in an ULTRIX environment. When a file is opened in append mode, the
- file pointer does not position itself at the end of file; if only
- system calls are used. How ever, with standard library results are as
- expected.
-
- Source code for both the versions are given below:
-
- /* This version uses the standard library */
-
- #include <stdio.h>
- #include <fcntl.h>
-
- main()
- {
- FILE * fp;
- if ((fp = fopen("junk","a")) == NULL)
- { printf( "Create a file called junk \n"); exit(0); }
- printf("The current fpos = %ld\n", ftell(fp));
- if(fwrite("junk",4, 1, fp) < 0) printf("error writing into file\n");
- printf("The current fpos after write = %ld\n", ftell(fp));
- fclose(fp);
- }
-
- /* This uses the unix system calls */
-
- #include <stdio.h>
- #include <fcntl.h>
-
- main()
- {
- int fp;
- if((fp = open("junk", O_WRONLY|O_APPEND)) < 0)
- {
- printf("Error writing into file\n");
- exit(0);
- }
- printf("The current fpos = %ld\n", tell(fp));
- if(write(fp,"junk",4) < 0) printf("error writing into file\n");
- printf("The current fposafter write = %ld\n", tell(fp));
- close(fp);
- }
-
- Reply to:
- shiva@vela.acs.oakland.edu
-
- --
- shiva
- --------------------------------------------------------------------------------
- Shivakumar C. Bettadapura E-mail : shiva@vela.acs.oakland.edu
- System Programer Office Phone # : (313) 370 - HELP
-