LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   syscalls.h (https://www.linuxquestions.org/questions/programming-9/syscalls-h-542991/)

ashlesha 04-03-2007 10:06 AM

syscalls.h
 
Hi,

I have written a program that uses the read() and write() system calls. I want the program to read from a wave file and write to /dev/audio.

Following is the code:

Quote:

#include<stdio.h>
#include "syscalls.h"

int main()
{
int a,b;
char c[2];

((a=read(0,c,2))==2) ? write(1,c,2): ((a==0) ? printf("EOF\n"): printf("error in reading\n"););
return(0);
}
My questions are these:

1) Is there a std header file called syscalls.h
2) When I compile this program using gcc, I get the following error:
Quote:

gcc: no input files
would this be the right command to give:

gcc wavread2.c xyz.wav -o wavread2.o

Thanks,
Ashlesha.

ashlesha 04-03-2007 10:24 AM

alright sorted out the error with the no input files...
but syscalls.h doesnt exist!

osor 04-03-2007 10:55 AM

You don’t need to use the system calls directly, just use the C wrappers that come with your C library. In short, do an “#include <unistd.h>” to get the read() and write() functions (taken from manpages). You don’t need any explicit linking since they are part of the standard C library.

If you for some reason, wish to use the system calls directly (or, more correctly, with a very thin wrapper), try something like:
Code:

#include <stdio.h>
#include <sys/syscall.h>

static inline ssize_t write(int fildes, const void *buf, size_t nbyte)
{
        return syscall (__NR_write, fildes, buf, nbyte);
}

static inline ssize_t read(int fildes, void *buf, size_t nbyte)
{
        return syscall (__NR_read, fildes, buf, nbyte);
}

int main()
{
        int a,b;
        char c[2];

        ((a=read(0,c,2))==2) ? write(1,c,2): ((a==0) ? printf("EOF\n"): printf("error in reading\n");
        return(0);
}


ashlesha 04-03-2007 10:56 AM

great! thank you!


All times are GMT -5. The time now is 06:58 AM.