Blame nss/nss_files_fopen.c

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