View | Details | Raw Unified | Return to bug 20338
Collapse All | Expand All

(-)a/gshadow/fgetsgent_r.c (-11 / +24 lines)
Lines 20-58 Link Here
20
#include <gshadow.h>
20
#include <gshadow.h>
21
#include <stdio.h>
21
#include <stdio.h>
22
22
23
#include <libio/iolibio.h>
24
#define flockfile(s) _IO_flockfile (s)
25
#define funlockfile(s) _IO_funlockfile (s)
26
23
/* Define a line parsing function using the common code
27
/* Define a line parsing function using the common code
24
   used in the nss_files module.  */
28
   used in the nss_files module.  */
25
29
26
#define STRUCTURE	sgrp
30
#define STRUCTURE	sgrp
27
#define ENTNAME		sgent
31
#define ENTNAME		sgent
28
#define	EXTERN_PARSER	1
32
#define EXTERN_PARSER	1
29
struct sgent_data {};
33
struct sgent_data {};
30
34
31
#include <nss/nss_files/files-parse.c>
35
#include <nss/nss_files/files-parse.c>
32
36
33
37
34
/* Read one shadow entry from the given stream.  */
38
/* Read one entry from the given stream.  */
35
int
39
int
36
__fgetsgent_r (FILE *stream, struct sgrp *resbuf, char *buffer, size_t buflen,
40
__fgetsgent_r (FILE *stream, struct sgrp *resbuf, char *buffer, size_t buflen,
37
	       struct sgrp **result)
41
	       struct sgrp **result)
38
{
42
{
39
  char *p;
43
  char *p;
44
  int parse_result;
40
45
41
  _IO_flockfile (stream);
46
  flockfile (stream);
42
  do
47
  do
43
    {
48
    {
44
      buffer[buflen - 1] = '\xff';
49
      buffer[buflen - 1] = '\xff';
45
      p = fgets_unlocked (buffer, buflen, stream);
50
      p = fgets_unlocked (buffer, buflen, stream);
46
      if (p == NULL && feof_unlocked (stream))
51
      if (__builtin_expect (p == NULL, 0) && feof_unlocked (stream))
47
	{
52
	{
48
	  _IO_funlockfile (stream);
53
	  funlockfile (stream);
49
	  *result = NULL;
54
	  *result = NULL;
50
	  __set_errno (ENOENT);
55
	  __set_errno (ENOENT);
51
	  return errno;
56
	  return errno;
52
	}
57
	}
53
      if (p == NULL || buffer[buflen - 1] != '\xff')
58
      if (__builtin_expect (p == NULL, 0) || buffer[buflen - 1] != '\xff')
54
	{
59
	{
55
	  _IO_funlockfile (stream);
60
	  funlockfile (stream);
56
	  *result = NULL;
61
	  *result = NULL;
57
	  __set_errno (ERANGE);
62
	  __set_errno (ERANGE);
58
	  return errno;
63
	  return errno;
Lines 61-73 __fgetsgent_r (FILE *stream, struct sgrp *resbuf, char *buffer, size_t buflen, Link Here
61
      /* Skip leading blanks.  */
66
      /* Skip leading blanks.  */
62
      while (isspace (*p))
67
      while (isspace (*p))
63
	++p;
68
	++p;
64
    } while (*p == '\0' || *p == '#' ||	/* Ignore empty and comment lines.  */
69
    } while (*p == '\0' || *p == '#'	/* Ignore empty and comment lines.  */
65
	     /* Parse the line.  If it is invalid, loop to
70
	     /* Parse the line.  If it is invalid, loop to
66
		get the next line of the file to parse.  */
71
		get the next line of the file to parse.  */
67
	     ! parse_line (buffer, (void *) resbuf, (void *) buffer, buflen,
72
	     || ! (parse_result = parse_line (p, resbuf,
68
			   &errno));
73
					      (void *) buffer, buflen,
74
					      &errno)));
75
76
  funlockfile (stream);
69
77
70
  _IO_funlockfile (stream);
78
  if (__builtin_expect (parse_result, 0) == -1)
79
    {
80
      /* The parser ran out of space.  */
81
      *result = NULL;
82
      return errno;
83
    }
71
84
72
  *result = resbuf;
85
  *result = resbuf;
73
  return 0;
86
  return 0;
(-)a/nss/nss_files/files-sgrp.c (-2 / +1 lines)
Lines 23-29 Link Here
23
#define DATABASE	"gshadow"
23
#define DATABASE	"gshadow"
24
struct sgent_data {};
24
struct sgent_data {};
25
25
26
/* Our parser function is already defined in sgetspent_r.c, so use that
26
/* Our parser function is already defined in sgetsgent_r.c, so use that
27
   to parse lines from the database file.  */
27
   to parse lines from the database file.  */
28
#define EXTERN_PARSER
28
#define EXTERN_PARSER
29
#include "files-parse.c"
29
#include "files-parse.c"
30
- 

Return to bug 20338