2

What is a system call in windows written in c? Cannot find an explanation on what it is in Google.

That is what we are asked to do: Your assignment is to implement Windows utility named HeadTail that receives a file name and an integer N as its parameters, and output to the console (standard output) N first lines of the file followed by N last lines reversed.

Vadiklk
  • 3,696
  • 5
  • 28
  • 44
  • Is this a homework question? If so, please add the homework tag. – Ken White Mar 12 '11 at 16:39
  • It is not, I was asked to write something using system calls, but I don't know what are they. – Vadiklk Mar 12 '11 at 16:40
  • You might want to post what it is that you were asked to write so people have a better idea of what it is, exactly, that you want to do. – jonmorgan Mar 12 '11 at 16:51
  • I am confused -- is your task to write HeadTail, or is your task to write HeadTail using Windows system calls? That is, if you write HeadTail without your code using Windows system calls directly, have you satisified the assignment? – Robᵩ Mar 12 '11 at 17:12
  • I need to use system calls only – Vadiklk Mar 12 '11 at 17:40
  • System calls on Windows are undocumented. You can safely assume that the teacher meant Winapi calls. Like CreateFile and ReadFile. – Hans Passant Mar 12 '11 at 18:00

2 Answers2

6

All of the core windows APIs exported from kernel32.dll and advapi32.dll are typically considered system calls (there are others and there are lower level APIs but this will probably meet your requirements (the lower level APIs are undocumented and much harder to use)).

To use them in your C application, if you're using visual studio or the Windows SDK build environment, you simply have to add:

#include <windows.h>

to your source file. You can then make any of the API calls from your C program.

You might have to add kernel32.lib when linking your application.

Larry Osterman
  • 16,086
  • 32
  • 60
5

http://en.wikipedia.org/wiki/System_call

In computing, a system call is how a program requests a service from an operating system's kernel that it does not normally have permission to run. System calls provide the interface between a process and the operating system. Most operations interacting with the system require permissions not available to a user level process, e.g. I/O performed with a device present on the system, or any form of communication with other processes requires the use of system calls.

For example fopen is not a system call, and ReadFile is .

Or more info at System call vs Function call

Community
  • 1
  • 1
The GiG
  • 2,571
  • 2
  • 28
  • 29