Article View: comp.unix.programmer
Article #116I am stumped on this one!!!
From: rajeev.dolas
Date: Fri, 24 Jul 1992 20:49
Date: Fri, 24 Jul 1992 20:49
121 lines
3001 bytes
3001 bytes
Hello all,
I have included a function from my code which doesn't work on a Sun
(690 w/ 4.1.2) but works on an Amdahl and I can't figure out why.
I am seeking help from the net after spending considerable amount of
time trying to debug this. I appreciate your help.
Thanks in advance.
Raj Dolas
raj@qsun.att.com
#include <stdio.h>
/* I have deleted lots of stuff to keep it simple for netters */
parse_conf(f2)
int f2;
{
char fname[80], ch, cmp[80];
char pars_wbuf[128];
char *pbuf;
char *cp_line;
char *tmp_line;
char *var, *getenv();
int comp, he;
int parse_ret;
int fd;
FILE *fp1, *fp2;
strcpy(fname, "/qsun/h5/raj/progs/acs/config/Star3/072392");
umask(0);
umask(066);
if((fp1 = fopen(fname, "w")) == NULL)
{
if((fp1 = fopen(fname, "w+")) == NULL)
printf("Cannot open fp1 in parse_conf()\n");
return(-78);
}
/** f2 was opened in another function with "w" and data was written */
if((fp2 = fdopen(f2, "r")) == NULL)
{
printf("Cannot open fp2 in parse_conf()\n");
return(-78);
}
/* As data was written to this file before, I must do a fseek */
if((he = fseek(fp2, 0L, 0)) < 0)
{
printf("fseek error in parse_conf()\n");
return(-78);
}
/* str_comp is my function which returns -1 if match is not found */
while((fgets(pars_wbuf, 80, fp2) != NULL) &&
((parse_ret = str_comp(cmp, pars_wbuf)) != 0))
{
pars_wbuf[strlen(pars_wbuf)] = '\0';
pbuf = pars_wbuf;
cp_line = (char *)malloc(sizeof(strlen(pars_wbuf)));
strcpy(cp_line, "\0");
tmp_line = cp_line;
if((comp = line_comp(pars_wbuf)) == 0)
;
else
{
/* Traverse thru pbuf, skip "
while(*pbuf != '\0')
{
if(*pbuf != 0x0D)
{
/* I was writing a char at a time to
the file before. This part works
on Amdahl but not on a sun. */
/**
ch = *pbuf;
fprintf(stdout, "%c", ch);
if((he = putc(ch, fp1)) < 0)
{
printf("pars_conf: Write error\n");
return(-13);
}
**/
/* Now I save it to a buffer */
*cp_line++ = *pbuf;
}
*pbuf++;
}
/* If I do a fputs to stdout, it works fine */
/**
fputs(tmp_line, stdout);
fflush(stdout);
**/
/* dbxtool shows the following error on this instr -
signal SEGV in malloc at 0xf773634
malloc+0x150: st %o0, [%15]
*/
fputs(tmp_line, fp1);
}
free(cp_line);
}
fclose(fp1);
if(fname)
free(*fname);
if(parse_ret != 0)
return(-89);
}
Technical Details
Message-ID:
<1992Jul24.204944.18516@cbfsb.cb.att.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!gatech!destroyer!caen!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!cbfsb!cbnewsf.cb.att.com!rajeevShow Full Headers
Complete Article Headers
Newsgroups: comp.unix.programmer Path: arc1-ca.pugleaf.net!sparky!uunet!gatech!destroyer!caen!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!cbfsb!cbnewsf.cb.att.com!rajeev From: rajeev@cbnewsf.cb.att.com (rajeev.dolas) Subject: I am stumped on this one!!! Message-ID: <1992Jul24.204944.18516@cbfsb.cb.att.com> Sender: news@cbfsb.cb.att.com Organization: AT&T Distribution: usa Date: Fri, 24 Jul 1992 20:49:44 GMT Lines: 124