Having a curious problem with the following piece of code.
The definition for user_record isn't important, and MAXIN is #defined to be 60.
The problem is that a temporary file name \tmp\tmp<PID> is created and stored
in character string tmpfile.
The file is created sucessfully and can be written into. It is then closed
with the fclose.
Just before the sprintf statement building mail_it in preparation for a system
call, tmpfile is printed out and is correct.
After the call to sprintf, tmpfile is printed out and contains only "gov"!!!
The string mail_it is created correctly and contains the proper filename
\tmp\tmp<PID>.
I know somehow I'm stepping on something, but I can't figure out how or where.
If you see my stupid error, please point it out. Everyone can have a big laugh
at my stupidity, BUT maybe I can get past this stumbling point and get the code
finished.
----
int mk_newuser(user_record,uid,pass)
struct urec *user_record ;
char *uid, *pass;
{
FILE *fptr;
char tmpfile[MAXIN];
char mail_it[MAXIN];
int i;
i = getpid();
sprintf(tmpfile,"/tmp/tmp%d",i);
printf("\n\n---------Generating new account for uid %s\n",uid);
printf("-------------User is %s %s %s\n\n",
user_record[0].data, user_record[1].data, user_record[2].data);
fptr = fopen(tmpfile,"w");
#if 0
fprintf(fptr,"\n\n---------Generating new account for uid %s\n",uid);
for(i=0;i<NRECS;i++)
{
fprintf(fptr,"%s\t%s\n",
user_record[i].prompt,user_record[i].data);
}
#endif
fclose(fptr);
printf("Before sprintf tmpfile = >%s<\n",tmpfile);
sprintf(mail_it,"/bin/cat %s | mail -s 'Applicant %s' %s",
tmpfile,uid,AUTH_AGENT);
printf("After sprintf tmpfile = >%s<\n",tmpfile);
printf("%s\n",mail_it);
#if 0
system(mail_it);
#endif
if( remove(tmpfile) != 0)
{
printf("tmpfile = >%s<\n",tmpfile);
perror("Error encountered attempting removal of tmpfile");
}
return(TRUE);
Quote:}