home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / unix / programm / 3900 < prev    next >
Encoding:
Text File  |  1992-07-25  |  2.8 KB  |  136 lines

  1. Newsgroups: comp.unix.programmer
  2. Path: sparky!uunet!gatech!destroyer!caen!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!cbfsb!cbnewsf.cb.att.com!rajeev
  3. From: rajeev@cbnewsf.cb.att.com (rajeev.dolas)
  4. Subject: I am stumped on this one!!!
  5. Message-ID: <1992Jul24.204944.18516@cbfsb.cb.att.com>
  6. Sender: news@cbfsb.cb.att.com
  7. Organization: AT&T
  8. Distribution: usa
  9. Date: Fri, 24 Jul 1992 20:49:44 GMT
  10. Lines: 124
  11.  
  12.  
  13. Hello all,
  14.  
  15.     I have included a function from my code which doesn't work on a Sun
  16.     (690 w/ 4.1.2) but works on an Amdahl and I can't figure out why. 
  17.     I am seeking help from the net after spending considerable amount of
  18.     time trying to debug this. I appreciate your help.
  19.  
  20.     Thanks in advance.
  21.  
  22.     Raj Dolas
  23.     raj@qsun.att.com
  24.  
  25.  
  26.  
  27. #include <stdio.h>
  28.  
  29. /* I have deleted lots of stuff to keep it simple for netters */
  30. parse_conf(f2)
  31. int f2;
  32. {
  33.  
  34.     char fname[80], ch, cmp[80];
  35.     char pars_wbuf[128];
  36.     char *pbuf;
  37.     char *cp_line;
  38.     char *tmp_line;
  39.     char *var, *getenv();
  40.     int comp, he;
  41.     int parse_ret;
  42.     int fd;
  43.     FILE *fp1, *fp2;
  44.  
  45.     strcpy(fname, "/qsun/h5/raj/progs/acs/config/Star3/072392");
  46.  
  47.     umask(0);
  48.     umask(066);
  49.     if((fp1 = fopen(fname, "w")) == NULL) 
  50.     {
  51.         if((fp1 = fopen(fname, "w+")) == NULL)
  52.         printf("Cannot open fp1 in parse_conf()\n");
  53.         return(-78);
  54.     }
  55.  
  56.     /** f2 was opened in another function with "w" and data was written */
  57.     if((fp2 = fdopen(f2, "r")) == NULL)
  58.     {
  59.         printf("Cannot open fp2 in parse_conf()\n");
  60.         return(-78);
  61.     }
  62.  
  63.     /* As data was written to this file before, I must do a fseek */
  64.     if((he = fseek(fp2, 0L, 0)) < 0)
  65.     {
  66.         printf("fseek error in parse_conf()\n");
  67.         return(-78);
  68.     }
  69.  
  70.     /* str_comp is my function which returns -1 if match is not found */
  71.     while((fgets(pars_wbuf, 80, fp2) != NULL) &&
  72.         ((parse_ret = str_comp(cmp, pars_wbuf)) != 0))
  73.     {
  74.         pars_wbuf[strlen(pars_wbuf)] = '\0';
  75.         pbuf = pars_wbuf;
  76.         cp_line = (char *)malloc(sizeof(strlen(pars_wbuf)));
  77.         strcpy(cp_line, "\0");
  78.         tmp_line = cp_line;
  79.  
  80.         if((comp = line_comp(pars_wbuf)) == 0)
  81.             ;
  82.         else 
  83.         {
  84.             /* Traverse thru pbuf, skip "
  85.             while(*pbuf != '\0')
  86.             {
  87.                 if(*pbuf != 0x0D)
  88.                 {
  89.                     /* I was writing a char at a time to
  90.                        the file before. This part works
  91.                        on Amdahl but not on a sun.    */
  92.  
  93.                     /**
  94.                     ch = *pbuf;
  95.                     fprintf(stdout, "%c", ch); 
  96.                     if((he = putc(ch, fp1)) < 0)
  97.                     {
  98.                          printf("pars_conf: Write error\n");
  99.                         return(-13);
  100.                     }
  101.                     **/
  102.  
  103.                     /* Now I save it to a buffer */
  104.                     *cp_line++ = *pbuf;
  105.                 }
  106.                 *pbuf++;
  107.             }
  108.             /* If I do a fputs to stdout, it works fine */
  109.             /**
  110.             fputs(tmp_line, stdout);
  111.             fflush(stdout);
  112.             **/
  113.  
  114.             /* dbxtool shows the following error on this instr -
  115.              signal SEGV in malloc at 0xf773634
  116.              malloc+0x150:    st    %o0, [%15]
  117.              */
  118.             fputs(tmp_line, fp1);
  119.         }
  120.         free(cp_line);
  121.     }
  122.     
  123.     fclose(fp1);
  124.  
  125.     
  126.     if(fname)
  127.         free(*fname);
  128.     
  129.     if(parse_ret != 0)
  130.         return(-89);
  131.  
  132. }
  133.  
  134.  
  135.  
  136.