linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* various doubts part 2
@ 2004-08-10  2:53 joy
  2004-08-10  7:04 ` Sascha Retzki
  0 siblings, 1 reply; 5+ messages in thread
From: joy @ 2004-08-10  2:53 UTC (permalink / raw)
  To: linux-c-programming

[-- Attachment #1: Type: text/plain, Size: 439 bytes --]

Heres the next installment of  the great series (please keep this series 
alive by donating to the ABsolutely Crappy  tv company (ABC).)

1) I'm trying to simulate what sendmail does when it has a command as a 
user,
    so I run my program like this:  a.out<text
    However , When it read()s , only one character is copied into the 
buffer.
if  text =

 >From : .........

the only cahracter in buffer is F.
how do I work around this?



[-- Attachment #2: mailLDA.c --]
[-- Type: text/plain, Size: 1035 bytes --]

#include<stdio.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<unistd.h>
#include<sys/timeb.h>
#include<ctype.h>
#include<fcntl.h>

#define MAX_FILENAME 20
#define MAX_BUFF 1024
#define FIFO_NAME "/tmp/Vpim_messenger"
char filename[MAX_FILENAME];

int main()
{
	struct timeb tp;
	int  outfile , fifo ,bytes_read,bytes_written, locked=1;
	char buff[MAX_BUFF];
	char message[MAX_BUFF] ; 
	ftime( &tp);
	sprintf(filename,"/tmp/%d.%d",tp.time,getpid());
	sprintf(message,"INFILE: %s",filename);
	outfile = open(filename,O_WRONLY|O_CREAT,S_IRWXU|S_IRWXO);
	while((bytes_read = read(STDIN_FILENO,buff,sizeof(buff))>0))
	{
		if((bytes_written = write(outfile , buff ,bytes_read))!=bytes_read)
		{
			fprintf(stderr,"write error");
			exit(1);
		}
	}
	fifo = open(FIFO_NAME,O_WRONLY,S_IWUSR);
	while(locked)
	{
		if(!(lockf(fifo,F_TEST,0)))
		{
			lockf(fifo,F_LOCK,0);
			locked = 0;
		}
	}
	if(bytes_written = write(fifo , message , sizeof(message))!= sizeof(message))
	{
		fprintf(stderr,"write error");
		exit(1);
	}
	
	return 1;
}

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2004-08-12 10:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-08-10  2:53 various doubts part 2 joy
2004-08-10  7:04 ` Sascha Retzki
2004-08-11  2:52   ` joy
2004-08-11 22:21     ` Luiz Fernando N. Capitulino
2004-08-12 10:49       ` joy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).