home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.programmer
- Path: sparky!uunet!cs.utexas.edu!torn!watserv1!watmath!undergrad.math.waterloo.edu!bbobak
- From: bbobak@undergrad.math.waterloo.edu (Brad Bobak)
- Subject: Re: I am stumped on this one!!!
- Message-ID: <Brx394.4qL@undergrad.math.waterloo.edu>
- Organization: University of Waterloo
- References: <1992Jul24.204944.18516@cbfsb.cb.att.com>
- Date: Fri, 24 Jul 1992 23:43:51 GMT
- Lines: 135
-
- In article <1992Jul24.204944.18516@cbfsb.cb.att.com> rajeev@cbnewsf.cb.att.com (rajeev.dolas) writes:
- >
- >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)));
-
-
- You're allocing the sizeof an int, which is likely four bytes.
- You also forgot to alloc space for the '\0'. Try it again with:
-
- cp_line = (char*)malloc(sizeof(strlen(pars_wbuf) + 1));
-
- > 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);
- >
- >}
- >
- >
- >
-
-
-
-