Blame nss/nss_files_fopen.c

Packit Service c73b7b
/* Open an nss_files database file.
Packit Service c73b7b
   Copyright (C) 2020 Free Software Foundation, Inc.
Packit Service c73b7b
   This file is part of the GNU C Library.
Packit Service c73b7b
Packit Service c73b7b
   The GNU C Library is free software; you can redistribute it and/or
Packit Service c73b7b
   modify it under the terms of the GNU Lesser General Public
Packit Service c73b7b
   License as published by the Free Software Foundation; either
Packit Service c73b7b
   version 2.1 of the License, or (at your option) any later version.
Packit Service c73b7b
Packit Service c73b7b
   The GNU C Library is distributed in the hope that it will be useful,
Packit Service c73b7b
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service c73b7b
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service c73b7b
   Lesser General Public License for more details.
Packit Service c73b7b
Packit Service c73b7b
   You should have received a copy of the GNU Lesser General Public
Packit Service c73b7b
   License along with the GNU C Library; if not, see
Packit Service c73b7b
   <https://www.gnu.org/licenses/>.  */
Packit Service c73b7b
Packit Service c73b7b
#include <nss_files.h>
Packit Service c73b7b
Packit Service c73b7b
#include <errno.h>
Packit Service c73b7b
#include <stdio_ext.h>
Packit Service c73b7b
Packit Service c73b7b
FILE *
Packit Service c73b7b
__nss_files_fopen (const char *path)
Packit Service c73b7b
{
Packit Service c73b7b
  FILE *fp = fopen (path, "rce");
Packit Service c73b7b
  if (fp == NULL)
Packit Service c73b7b
    return NULL;
Packit Service c73b7b
Packit Service c73b7b
  /* The stream is not shared across threads.  */
Packit Service c73b7b
  __fsetlocking (fp, FSETLOCKING_BYCALLER);
Packit Service c73b7b
Packit Service c73b7b
  /* This tells libio that the file is seekable, and that fp->_offset
Packit Service c73b7b
     is correct, ensuring that __ftello64 is efficient (bug 26257).  */
Packit Service c73b7b
  if (__fseeko64 (fp, 0, SEEK_SET) < 0)
Packit Service c73b7b
    {
Packit Service c73b7b
      /* nss_files requires seekable files, to deal with repeated
Packit Service c73b7b
         reads of the same line after reporting ERANGE.  */
Packit Service c73b7b
      fclose (fp);
Packit Service c73b7b
      __set_errno (ESPIPE);
Packit Service c73b7b
      return NULL;
Packit Service c73b7b
    }
Packit Service c73b7b
Packit Service c73b7b
  return fp;
Packit Service c73b7b
}
Packit Service c73b7b
libc_hidden_def (__nss_files_fopen)