1  /* Simplified version of test to ensure we issue a FILE * leak diagnostic,
       2     reproducing a feasibility issue.
       3     Adapted from intl/localealias.c, with all #includes removed.  */
       4  
       5  /* { dg-do "compile" } */
       6  
       7  /* Handle aliases for locale names.
       8     Copyright (C) 1995-1999, 2000-2001, 2003 Free Software Foundation, Inc.
       9  
      10     This program is free software; you can redistribute it and/or modify it
      11     under the terms of the GNU Library General Public License as published
      12     by the Free Software Foundation; either version 2, or (at your option)
      13     any later version.
      14  
      15     This program is distributed in the hope that it will be useful,
      16     but WITHOUT ANY WARRANTY; without even the implied warranty of
      17     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      18     Library General Public License for more details.
      19  
      20     You should have received a copy of the GNU Library General Public
      21     License along with this program; if not, write to the Free Software
      22     Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301,
      23     USA.  */
      24  
      25  /* Minimal version of system headers.  */
      26  
      27  typedef __SIZE_TYPE__ size_t;
      28  #define NULL ((void *)0)
      29  
      30  typedef struct _IO_FILE FILE;
      31  extern FILE *fopen (const char *__restrict __filename,
      32  		    const char *__restrict __modes);
      33  extern size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);
      34  extern int fclose (FILE *__stream);
      35  
      36  extern int isspace (int) __attribute__((__nothrow__, __leaf__));
      37  
      38  /* Cleaned-up body of localealias.c follows.  */
      39  
      40  size_t
      41  read_alias_file (const char *fname, int fname_len)
      42  {
      43    FILE *fp;
      44    size_t added;
      45    char buf[400];
      46    char *alias;
      47    char *value;
      48    char *cp;
      49  
      50    fp = fopen (fname, "r"); /* { dg-message "opened here" } */
      51    if (fp == NULL)
      52      return 0;
      53  
      54    if (fread (buf, sizeof buf, 1, fp) != 1)
      55      {
      56        fclose (fp);
      57        return 0;
      58      }
      59  
      60    cp = buf;
      61  
      62    /* Ignore leading white space.  */
      63    while (isspace ((unsigned char)cp[0]))
      64      ++cp;
      65  
      66    if (cp[0] != '\0' && cp[0] != '#')
      67      {
      68        alias = cp++;
      69        while (cp[0] != '\0' && !isspace ((unsigned char)cp[0]))
      70  	++cp;
      71        if (cp[0] != '\0')
      72  	*cp++ = '\0';
      73  
      74        while (isspace ((unsigned char)cp[0]))
      75  	++cp;
      76  
      77        if (cp[0] != '\0')
      78  	return 42; /* { dg-warning "leak of FILE 'fp'" } */
      79      }
      80  
      81    fclose(fp);
      82  
      83    return 0;
      84  }