🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.msdos.programmer
Article #1473

BC++2.0 lseek problem(ALSO:lseek() question)

#1473
From: Zhuo Zang
Date: Sat, 12 Sep 1992 23:52
47 lines
1473 bytes
Hello,
the following program using lseek will
give different results in BC++2.0 than
that of in UNIX.
the BC++2.0 will print the last character twice.

------- foo.c ----------
/* use bcc -DMSDOS foo.c to compile in BC++i
   use cc foo.c to compile under UNIX */
#include <stdio.h>
#include <fcntl.h>
#ifdef MSDOS 
#include <io.h>
#else
#include <sys/file.h>
#endif

char *sp, buf[BUFSIZ];
int fd;
int get(int fd, long pos, char *buf, int n);

int main()
{
  sp = buf;
  fd = open("foo.c", O_RDONLY, 0);
  get(fd, 3, sp, 20);
/* I have question here, where does the sp point now? 
   please notice the assignment sp = '\0', and the output
   of the program */
  puts(sp);
  sp = '\0';
  puts(buf);
  return 0;
}

int get(int fd, long pos, char *buf, int n)
{
    if (lseek(fd, pos, 0) >= 0)
	return read(fd, buf, n);
    else
	return -1;
}

-- 
Zhuo Zang[~{j0WA~}]
Department of Statistics
University of Florida            Email: zzang@stat.ufl.edu
Technical Details
Message-ID: <1992Sep12.235241.23213@eng.ufl.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!sdd.hp.com!uakari.primate.wisc.edu!eng.ufl.edu!manta!zzang

Show Full Headers
Complete Article Headers
Newsgroups: comp.os.msdos.programmer,comp.lang.c
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!sdd.hp.com!uakari.primate.wisc.edu!eng.ufl.edu!manta!zzang
From: zzang@stat.ufl.edu (Zhuo Zang)
Subject: BC++2.0 lseek problem(ALSO:lseek() question)
Message-ID: <1992Sep12.235241.23213@eng.ufl.edu>
Originator: zzang@manta
Sender: news@eng.ufl.edu (Usenet Diskhog System)
Organization: University of Florida
Distribution: usa
Date: Sat, 12 Sep 92 23:52:41 GMT
Lines: 47