LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 04-03-2007, 10:06 AM   #1
ashlesha
Member
 
Registered: May 2005
Location: PA
Distribution: Ubuntu
Posts: 204

Rep: Reputation: 30
Unhappy 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.
 
Old 04-03-2007, 10:24 AM   #2
ashlesha
Member
 
Registered: May 2005
Location: PA
Distribution: Ubuntu
Posts: 204

Original Poster
Rep: Reputation: 30
alright sorted out the error with the no input files...
but syscalls.h doesnt exist!
 
Old 04-03-2007, 10:55 AM   #3
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 70
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);
}
 
Old 04-03-2007, 10:56 AM   #4
ashlesha
Member
 
Registered: May 2005
Location: PA
Distribution: Ubuntu
Posts: 204

Original Poster
Rep: Reputation: 30
great! thank you!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
messing with syscalls m00t00 Programming 2 11-27-2004 03:28 PM
What are the drawbacks of syscalls and context switches? shy Programming 7 11-25-2004 02:03 PM
rAPI with syscalls blietaer Programming 0 02-02-2004 02:49 AM


All times are GMT -5. The time now is 02:03 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration