Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

jamesapp

macrumors 6502a
Original poster
Mar 7, 2008
544
0
reading from a book The C Programming Language by Brian W. Kernighan and Dennis M. Ritchie. In the last chapter of the book, they discuss a file called syscalls.h,

from the book:

"We have collected function prototypes for the system calls into a file called syscalls.h so we can include it in the programs of this chapter. This name is not standard however."

I don't know where these functions are coming from.
the first program in the chapter is a program to copy input to output.
here is my source file which i called inputout.c:

Code:
#include "syscalls.h"

main()  /* copy input to output */
{
  char buf[BUFSIZ];
  int n;
  
  while ((n = read(0, buf, BUFSIZ)) > 0)
      write(1, buf, n);
  return 0;
}

when i went to compile it i got error messages saying that the file syscalls.h doesen't exist. does anyone know anything about syscalls.h?
 

brn2ski00

macrumors 68020
Aug 16, 2007
2,242
14
MA
That was the same book that I used in college as well. Small world....

It sounds like syscalls.h is a KR specific header file. You may need to install or copy those files from (where ever) into your directory where the program is.
 

drivefast

macrumors regular
Mar 13, 2008
128
0
try
Code:
#include "stdio.h"
instead of syscalls.h. maybe the syscalls.h they have in the book already includes stdio.
 

ChrisA

macrumors G5
Jan 5, 2006
12,917
2,169
Redondo Beach, California
reading from a book The C Programming Language by Brian W. Kernighan and Dennis M. Ritchie. In the last chapter of the book, they discuss a file called syscalls.h,

K&R is a good book to have for historic reasons. It shows what programming C was like in the early days before ANSI C was the standard. I keep my copy of K&R right next to Griiswald's "SNOBOL" book, the MIT LISP 1.4 manual and Wirth's Pascal book. All of these are classics that are decades out of date. I got into programming back when Unix was the hot new thing in the early 70s

Today if you don't know what dot-H file to include just look up the man page for that funtion. I cut and paste the #include right out of the man page. After doing this a few times you learn the common ones.
 

ScoobyMcDoo

macrumors 65816
Nov 26, 2007
1,188
37
Austin, TX
Hmmm. I have the first edition still - it doesn't mention the syscalls.h file. Not sure why it would for that example. On my linux box, there is a syscalls.h file, but it would not be needed for this example.

As ChrisA said, use the man page - in your case type "man 2 read" and it will tell you what headers you need to include:

NAME
pread, read, readv -- read input

LIBRARY
Standard C Library (libc, -lc)

SYNOPSIS
#include <sys/types.h>
#include <sys/uio.h>
#include <unistd.h>
 

pilotError

macrumors 68020
Apr 12, 2006
2,237
4
Long Island
In chapter 1 or 2 of the book, they created a header for all the future examples in the book. That's what the include file is.

I'm sure if you look in the TOC, you'll find the page number of the listing.
 

psingh01

macrumors 68000
Apr 19, 2004
1,586
629
sounds like it is a file they created themselves like other say. might even be listed in the book.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.