From: joy <gracecott@sancharnet.in>
To: linux-c-programming@vger.kernel.org
Subject: various doubts part 2
Date: Tue, 10 Aug 2004 08:23:13 +0530 [thread overview]
Message-ID: <41183899.9000203@sancharnet.in> (raw)
[-- 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;
}
next reply other threads:[~2004-08-10 2:53 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-08-10 2:53 joy [this message]
2004-08-10 7:04 ` various doubts part 2 Sascha Retzki
2004-08-11 2:52 ` joy
2004-08-11 22:21 ` Luiz Fernando N. Capitulino
2004-08-12 10:49 ` joy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=41183899.9000203@sancharnet.in \
--to=gracecott@sancharnet.in \
--cc=linux-c-programming@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).