Blame nis/nis_error.c

Packit 6c4009
/* Copyright (c) 1997-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
   Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#include <errno.h>
Packit 6c4009
#include <syslog.h>
Packit 6c4009
#include <string.h>
Packit 6c4009
#include <libintl.h>
Packit 6c4009
#include <rpcsvc/nis.h>
Packit 6c4009
#include <shlib-compat.h>
Packit 6c4009
Packit 6c4009
Packit 6c4009
#define MF(line) MF1 (line)
Packit 6c4009
#define MF1(line) str##line
Packit 6c4009
static const union msgstr_t
Packit 6c4009
{
Packit 6c4009
  struct
Packit 6c4009
  {
Packit 6c4009
#define S(s) char MF(__LINE__)[sizeof (s)];
Packit 6c4009
#include "nis_error.h"
Packit 6c4009
#undef S
Packit 6c4009
  };
Packit 6c4009
  char str[0];
Packit 6c4009
} msgstr =
Packit 6c4009
  {
Packit 6c4009
    {
Packit 6c4009
#define S(s) s,
Packit 6c4009
#include "nis_error.h"
Packit 6c4009
#undef S
Packit 6c4009
    }
Packit 6c4009
  };
Packit 6c4009
Packit 6c4009
static const unsigned short int msgidx[] =
Packit 6c4009
  {
Packit 6c4009
#define S(s) offsetof (union msgstr_t, MF (__LINE__)),
Packit 6c4009
#include "nis_error.h"
Packit 6c4009
#undef S
Packit 6c4009
  };
Packit 6c4009
Packit 6c4009
Packit 6c4009
const char *
Packit 6c4009
nis_sperrno (const nis_error status)
Packit 6c4009
{
Packit 6c4009
  if (status >= sizeof (msgidx) / sizeof (msgidx[0]))
Packit 6c4009
    return "???";
Packit 6c4009
  else
Packit 6c4009
    return gettext (msgstr.str + msgidx[status]);
Packit 6c4009
}
Packit 6c4009
libnsl_hidden_nolink_def (nis_sperrno, GLIBC_2_1)
Packit 6c4009
Packit 6c4009
void
Packit 6c4009
nis_perror (const nis_error status, const char *label)
Packit 6c4009
{
Packit 6c4009
  fprintf (stderr, "%s: %s\n", label, nis_sperrno (status));
Packit 6c4009
}
Packit 6c4009
libnsl_hidden_nolink_def (nis_perror, GLIBC_2_1)
Packit 6c4009
Packit 6c4009
void
Packit 6c4009
nis_lerror (const nis_error status, const char *label)
Packit 6c4009
{
Packit 6c4009
  syslog (LOG_ERR, "%s: %s", label, nis_sperrno (status));
Packit 6c4009
}
Packit 6c4009
libnsl_hidden_nolink_def (nis_lerror, GLIBC_2_1)
Packit 6c4009
Packit 6c4009
char *
Packit 6c4009
nis_sperror_r (const nis_error status, const char *label,
Packit 6c4009
	       char *buffer, size_t buflen)
Packit 6c4009
{
Packit 6c4009
  if (snprintf (buffer, buflen, "%s: %s", label, nis_sperrno (status))
Packit 6c4009
      >= buflen)
Packit 6c4009
    {
Packit 6c4009
      __set_errno (ERANGE);
Packit 6c4009
      return NULL;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  return buffer;
Packit 6c4009
}
Packit 6c4009
libnsl_hidden_nolink_def (nis_sperror_r, GLIBC_2_1)
Packit 6c4009
Packit 6c4009
char *
Packit 6c4009
nis_sperror (const nis_error status, const char *label)
Packit 6c4009
{
Packit 6c4009
  static char buffer[NIS_MAXNAMELEN + 1];
Packit 6c4009
Packit 6c4009
  return nis_sperror_r (status, label, buffer, sizeof (buffer));
Packit 6c4009
}
Packit 6c4009
libnsl_hidden_nolink_def (nis_sperror, GLIBC_2_1)