pmt: e2fsprogs: cleanup
This commit is contained in:
105
e2fsprogs/lib/et/com_err.c
Normal file
105
e2fsprogs/lib/et/com_err.c
Normal file
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Copyright 1987, 1988 by MIT Student Information Processing Board.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software and
|
||||
* its documentation for any purpose is hereby granted, provided that
|
||||
* the names of M.I.T. and the M.I.T. S.I.P.B. not be used in
|
||||
* advertising or publicity pertaining to distribution of the software
|
||||
* without specific, written prior permission. M.I.T. and the
|
||||
* M.I.T. S.I.P.B. make no representations about the suitability of
|
||||
* this software for any purpose. It is provided "as is" without
|
||||
* express or implied warranty.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include <stdio.h>
|
||||
#ifdef HAVE_TERMIOS_H
|
||||
#include <termios.h>
|
||||
#endif
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include "com_err.h"
|
||||
#include "error_table.h"
|
||||
#include "internal.h"
|
||||
|
||||
static void
|
||||
default_com_err_proc (const char *whoami, errcode_t code, const
|
||||
char *fmt, va_list args)
|
||||
COM_ERR_ATTR((format(printf, 3, 0)));
|
||||
|
||||
static void
|
||||
default_com_err_proc (const char *whoami, errcode_t code, const
|
||||
char *fmt, va_list args)
|
||||
{
|
||||
int do_cr = 1, fd = fileno(stderr);
|
||||
|
||||
if (whoami) {
|
||||
fputs(whoami, stderr);
|
||||
fputs(": ", stderr);
|
||||
}
|
||||
if (code) {
|
||||
fputs(error_message(code), stderr);
|
||||
fputs(" ", stderr);
|
||||
}
|
||||
if (fmt) {
|
||||
vfprintf (stderr, fmt, args);
|
||||
}
|
||||
if (!isatty(fd))
|
||||
do_cr = 0;
|
||||
#ifdef HAVE_TERMIOS_H
|
||||
else {
|
||||
struct termios t;
|
||||
|
||||
if ((tcgetattr(fd, &t)) == 0 &&
|
||||
(t.c_oflag & OPOST) && (t.c_oflag & ONLCR))
|
||||
do_cr = 0;
|
||||
}
|
||||
#endif
|
||||
if (do_cr)
|
||||
fputc('\r', stderr);
|
||||
fputc('\n', stderr);
|
||||
fflush(stderr);
|
||||
}
|
||||
|
||||
typedef void (*errf) (const char *, errcode_t, const char *, va_list)
|
||||
COM_ERR_ATTR((format(printf, 3, 0)));
|
||||
|
||||
errf com_err_hook = default_com_err_proc;
|
||||
|
||||
void com_err_va (const char *whoami, errcode_t code, const char *fmt,
|
||||
va_list args)
|
||||
{
|
||||
(*com_err_hook) (whoami, code, fmt, args);
|
||||
}
|
||||
|
||||
void com_err (const char *whoami,
|
||||
errcode_t code,
|
||||
const char *fmt, ...)
|
||||
{
|
||||
va_list pvar;
|
||||
|
||||
if (!com_err_hook)
|
||||
com_err_hook = default_com_err_proc;
|
||||
va_start(pvar, fmt);
|
||||
com_err_va (whoami, code, fmt, pvar);
|
||||
va_end(pvar);
|
||||
}
|
||||
|
||||
errf set_com_err_hook(errf new_proc)
|
||||
{
|
||||
errf x = com_err_hook;
|
||||
|
||||
if (new_proc)
|
||||
com_err_hook = new_proc;
|
||||
else
|
||||
com_err_hook = default_com_err_proc;
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
errf reset_com_err_hook(void) {
|
||||
errf x = com_err_hook;
|
||||
com_err_hook = default_com_err_proc;
|
||||
return x;
|
||||
}
|
||||
120
e2fsprogs/lib/et/com_right.c
Normal file
120
e2fsprogs/lib/et/com_right.c
Normal file
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* com_right.c -- provide Heimdall / Kerberos4kth com_err interfaces
|
||||
* for backwards compatibility
|
||||
*
|
||||
* Copyright (c) 2003 by Theodore Ts'o
|
||||
*
|
||||
* Taken from lib/com_err/error.c from Kerberos4kth distribution.
|
||||
*
|
||||
* Copyright (c) 1997, 1998, 2001 Kungliga Tekniska H<>gskolan
|
||||
* (Royal Institute of Technology, Stockholm, Sweden).
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "com_err.h"
|
||||
#include "error_table.h"
|
||||
|
||||
const char *
|
||||
com_right(struct et_list *list, long code)
|
||||
{
|
||||
struct et_list *p;
|
||||
for (p = list; p; p = p->next) {
|
||||
if (code >= p->table->base && code < p->table->base + p->table->n_msgs)
|
||||
return p->table->msgs[code - p->table->base];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char *
|
||||
com_right_r(struct et_list *list, long code, char *str, size_t len)
|
||||
{
|
||||
struct et_list *p;
|
||||
for (p = list; p; p = p->next) {
|
||||
if ((code >= p->table->base) &&
|
||||
(code < p->table->base + p->table->n_msgs)) {
|
||||
strncpy(str, p->table->msgs[code - p->table->base], len);
|
||||
str[len-1] = '\0';
|
||||
return str;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct foobar {
|
||||
struct et_list etl;
|
||||
struct error_table tab;
|
||||
};
|
||||
|
||||
/*
|
||||
* We provide this routine for compatibility with Heimdall generated
|
||||
* foo_err.c files, but we don't use this ourselves for foo_err.c
|
||||
* files generated by our compile_et. This is so our foo_err.c
|
||||
* files can be used with older com_err libraries without running
|
||||
* afoul of dependencies.
|
||||
*/
|
||||
void
|
||||
initialize_error_table_r(struct et_list **list,
|
||||
const char **messages,
|
||||
int num_errors,
|
||||
long base)
|
||||
{
|
||||
struct et_list *et, **end;
|
||||
struct error_table *tab;
|
||||
struct foobar *f;
|
||||
|
||||
for (end = list, et = *list; et; end = &et->next, et = et->next)
|
||||
if (et->table->msgs == messages)
|
||||
return;
|
||||
f = malloc(sizeof(*f));
|
||||
if (f == NULL)
|
||||
return;
|
||||
et = &f->etl;
|
||||
et->table = tab = &f->tab;
|
||||
tab->msgs = messages;
|
||||
tab->n_msgs = num_errors;
|
||||
tab->base = base;
|
||||
et->next = NULL;
|
||||
*end = et;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
free_error_table(struct et_list *et)
|
||||
{
|
||||
while(et){
|
||||
struct et_list *p = et;
|
||||
et = et->next;
|
||||
free(p);
|
||||
}
|
||||
}
|
||||
355
e2fsprogs/lib/et/error_message.c
Normal file
355
e2fsprogs/lib/et/error_message.c
Normal file
@@ -0,0 +1,355 @@
|
||||
/*
|
||||
* $Header$
|
||||
* $Source$
|
||||
* $Locker$
|
||||
*
|
||||
* Copyright 1987 by the Student Information Processing Board
|
||||
* of the Massachusetts Institute of Technology
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software and
|
||||
* its documentation for any purpose is hereby granted, provided that
|
||||
* the names of M.I.T. and the M.I.T. S.I.P.B. not be used in
|
||||
* advertising or publicity pertaining to distribution of the software
|
||||
* without specific, written prior permission. M.I.T. and the
|
||||
* M.I.T. S.I.P.B. make no representations about the suitability of
|
||||
* this software for any purpose. It is provided "as is" without
|
||||
* express or implied warranty.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#ifdef HAVE_SYS_PRCTL_H
|
||||
#include <sys/prctl.h>
|
||||
#else
|
||||
#define PR_GET_DUMPABLE 3
|
||||
#endif
|
||||
#if (!defined(HAVE_PRCTL) && defined(linux))
|
||||
#include <sys/syscall.h>
|
||||
#endif
|
||||
#ifdef HAVE_SEMAPHORE_H
|
||||
#include <semaphore.h>
|
||||
#endif
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#if HAVE_FCNTL
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
#if HAVE_SYS_TYPES_H
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
#include "com_err.h"
|
||||
#include "error_table.h"
|
||||
#include "internal.h"
|
||||
|
||||
#ifdef TLS
|
||||
#define THREAD_LOCAL static TLS
|
||||
#else
|
||||
#define THREAD_LOCAL static
|
||||
#endif
|
||||
|
||||
THREAD_LOCAL char buffer[25];
|
||||
|
||||
struct et_list * _et_list = (struct et_list *) NULL;
|
||||
struct et_list * _et_dynamic_list = (struct et_list *) NULL;
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define COMERR_ATTR(x) __attribute__(x)
|
||||
#else
|
||||
#define COMERR_ATTR(x)
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SEM_INIT
|
||||
static sem_t _et_lock;
|
||||
static int _et_lock_initialized;
|
||||
|
||||
static void COMERR_ATTR((constructor)) setup_et_lock(void)
|
||||
{
|
||||
sem_init(&_et_lock, 0, 1);
|
||||
_et_lock_initialized = 1;
|
||||
}
|
||||
|
||||
static void COMERR_ATTR((destructor)) fini_et_lock(void)
|
||||
{
|
||||
sem_destroy(&_et_lock);
|
||||
_et_lock_initialized = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
int et_list_lock(void)
|
||||
{
|
||||
#ifdef HAVE_SEM_INIT
|
||||
if (!_et_lock_initialized)
|
||||
setup_et_lock();
|
||||
return sem_wait(&_et_lock);
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
int et_list_unlock(void)
|
||||
{
|
||||
#ifdef HAVE_SEM_INIT
|
||||
if (_et_lock_initialized)
|
||||
return sem_post(&_et_lock);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
typedef char *(*gettextf) (const char *);
|
||||
|
||||
static gettextf com_err_gettext = NULL;
|
||||
|
||||
gettextf set_com_err_gettext(gettextf new_proc)
|
||||
{
|
||||
gettextf x = com_err_gettext;
|
||||
|
||||
com_err_gettext = new_proc;
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
#ifdef __GNU__
|
||||
#define SYS_ERR_BASE 0x40000000
|
||||
#else
|
||||
#define SYS_ERR_BASE 0
|
||||
#endif
|
||||
|
||||
const char * error_message (errcode_t code)
|
||||
{
|
||||
int offset;
|
||||
struct et_list *et;
|
||||
errcode_t table_num;
|
||||
int started = 0;
|
||||
char *cp;
|
||||
|
||||
offset = (int) (code & ((1<<ERRCODE_RANGE)-1));
|
||||
table_num = code - offset;
|
||||
if (table_num == SYS_ERR_BASE) {
|
||||
#ifdef HAS_SYS_ERRLIST
|
||||
if (code < sys_nerr)
|
||||
return(sys_errlist[code]);
|
||||
else
|
||||
goto oops;
|
||||
#else
|
||||
cp = strerror(code);
|
||||
if (cp)
|
||||
return(cp);
|
||||
else
|
||||
goto oops;
|
||||
#endif
|
||||
}
|
||||
et_list_lock();
|
||||
for (et = _et_list; et; et = et->next) {
|
||||
if ((et->table->base & 0xffffffL) == (table_num & 0xffffffL)) {
|
||||
/* This is the right table */
|
||||
if (et->table->n_msgs <= offset) {
|
||||
break;
|
||||
} else {
|
||||
const char *msg = et->table->msgs[offset];
|
||||
et_list_unlock();
|
||||
if (com_err_gettext)
|
||||
return (*com_err_gettext)(msg);
|
||||
else
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (et = _et_dynamic_list; et; et = et->next) {
|
||||
if ((et->table->base & 0xffffffL) == (table_num & 0xffffffL)) {
|
||||
/* This is the right table */
|
||||
if (et->table->n_msgs <= offset) {
|
||||
break;
|
||||
} else {
|
||||
const char *msg = et->table->msgs[offset];
|
||||
et_list_unlock();
|
||||
if (com_err_gettext)
|
||||
return (*com_err_gettext)(msg);
|
||||
else
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
}
|
||||
et_list_unlock();
|
||||
oops:
|
||||
strcpy (buffer, "Unknown code ");
|
||||
if (table_num) {
|
||||
strcat (buffer, error_table_name (table_num));
|
||||
strcat (buffer, " ");
|
||||
}
|
||||
for (cp = buffer; *cp; cp++)
|
||||
;
|
||||
if (offset >= 100) {
|
||||
*cp++ = '0' + offset / 100;
|
||||
offset %= 100;
|
||||
started++;
|
||||
}
|
||||
if (started || offset >= 10) {
|
||||
*cp++ = '0' + offset / 10;
|
||||
offset %= 10;
|
||||
}
|
||||
*cp++ = '0' + offset;
|
||||
*cp = '\0';
|
||||
return(buffer);
|
||||
}
|
||||
|
||||
/*
|
||||
* This routine will only return a value if the we are not running as
|
||||
* a privileged process.
|
||||
*/
|
||||
static char *safe_getenv(const char *arg)
|
||||
{
|
||||
#if !defined(_WIN32)
|
||||
if ((getuid() != geteuid()) || (getgid() != getegid()))
|
||||
return NULL;
|
||||
#endif
|
||||
#if HAVE_PRCTL
|
||||
if (prctl(PR_GET_DUMPABLE, 0, 0, 0, 0) == 0)
|
||||
return NULL;
|
||||
#else
|
||||
#if (defined(linux) && defined(SYS_prctl))
|
||||
if (syscall(SYS_prctl, PR_GET_DUMPABLE, 0, 0, 0, 0) == 0)
|
||||
return NULL;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_SECURE_GETENV)
|
||||
return secure_getenv(arg);
|
||||
#elif defined(HAVE___SECURE_GETENV)
|
||||
return __secure_getenv(arg);
|
||||
#else
|
||||
return getenv(arg);
|
||||
#endif
|
||||
}
|
||||
|
||||
#define DEBUG_INIT 0x8000
|
||||
#define DEBUG_ADDREMOVE 0x0001
|
||||
|
||||
static int debug_mask = 0;
|
||||
static FILE *debug_f = 0;
|
||||
|
||||
static void init_debug(void)
|
||||
{
|
||||
char *dstr, *fn, *tmp;
|
||||
|
||||
if (debug_mask & DEBUG_INIT)
|
||||
return;
|
||||
|
||||
dstr = getenv("COMERR_DEBUG");
|
||||
if (dstr) {
|
||||
debug_mask = strtoul(dstr, &tmp, 0);
|
||||
if (*tmp || errno)
|
||||
debug_mask = 0;
|
||||
}
|
||||
|
||||
debug_mask |= DEBUG_INIT;
|
||||
if (debug_mask == DEBUG_INIT)
|
||||
return;
|
||||
|
||||
fn = safe_getenv("COMERR_DEBUG_FILE");
|
||||
if (fn)
|
||||
debug_f = fopen(fn, "a");
|
||||
if (!debug_f)
|
||||
debug_f = fopen("/dev/tty", "a");
|
||||
if (debug_f) {
|
||||
#ifdef HAVE_FCNTL
|
||||
int fd = fileno(debug_f);
|
||||
|
||||
if (fd >= 0) {
|
||||
int flags = fcntl(fd, F_GETFD);
|
||||
|
||||
if (flags >= 0)
|
||||
flags = fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
|
||||
if (flags < 0) {
|
||||
fprintf(debug_f, "Couldn't set FD_CLOEXEC "
|
||||
"on debug FILE: %s\n", strerror(errno));
|
||||
fclose(debug_f);
|
||||
debug_f = NULL;
|
||||
debug_mask = DEBUG_INIT;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
} else
|
||||
debug_mask = DEBUG_INIT;
|
||||
}
|
||||
|
||||
/*
|
||||
* New interface provided by krb5's com_err library
|
||||
*/
|
||||
errcode_t add_error_table(const struct error_table * et)
|
||||
{
|
||||
struct et_list *el;
|
||||
|
||||
if (!(el = (struct et_list *) malloc(sizeof(struct et_list))))
|
||||
return ENOMEM;
|
||||
|
||||
if (et_list_lock() != 0) {
|
||||
free(el);
|
||||
return errno;
|
||||
}
|
||||
|
||||
el->table = et;
|
||||
el->next = _et_dynamic_list;
|
||||
_et_dynamic_list = el;
|
||||
|
||||
init_debug();
|
||||
if (debug_mask & DEBUG_ADDREMOVE)
|
||||
fprintf(debug_f, "add_error_table: %s (0x%p)\n",
|
||||
error_table_name(et->base),
|
||||
(const void *) et);
|
||||
|
||||
et_list_unlock();
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* New interface provided by krb5's com_err library
|
||||
*/
|
||||
errcode_t remove_error_table(const struct error_table * et)
|
||||
{
|
||||
struct et_list *el;
|
||||
struct et_list *el2 = 0;
|
||||
|
||||
if (et_list_lock() != 0)
|
||||
return ENOENT;
|
||||
|
||||
el = _et_dynamic_list;
|
||||
init_debug();
|
||||
while (el) {
|
||||
if (el->table->base == et->base) {
|
||||
if (el2) /* Not the beginning of the list */
|
||||
el2->next = el->next;
|
||||
else
|
||||
_et_dynamic_list = el->next;
|
||||
(void) free(el);
|
||||
if (debug_mask & DEBUG_ADDREMOVE)
|
||||
fprintf(debug_f,
|
||||
"remove_error_table: %s (0x%p)\n",
|
||||
error_table_name(et->base),
|
||||
(const void *) et);
|
||||
et_list_unlock();
|
||||
return 0;
|
||||
}
|
||||
el2 = el;
|
||||
el = el->next;
|
||||
}
|
||||
if (debug_mask & DEBUG_ADDREMOVE)
|
||||
fprintf(debug_f, "remove_error_table FAILED: %s (0x%p)\n",
|
||||
error_table_name(et->base),
|
||||
(const void *) et);
|
||||
et_list_unlock();
|
||||
return ENOENT;
|
||||
}
|
||||
|
||||
/*
|
||||
* Variant of the interface provided by Heimdal's com_err library
|
||||
*/
|
||||
void
|
||||
add_to_error_table(struct et_list *new_table)
|
||||
{
|
||||
add_error_table(new_table->table);
|
||||
}
|
||||
43
e2fsprogs/lib/et/et_name.c
Normal file
43
e2fsprogs/lib/et/et_name.c
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 1987 by MIT Student Information Processing Board
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software and
|
||||
* its documentation for any purpose is hereby granted, provided that
|
||||
* the names of M.I.T. and the M.I.T. S.I.P.B. not be used in
|
||||
* advertising or publicity pertaining to distribution of the software
|
||||
* without specific, written prior permission. M.I.T. and the
|
||||
* M.I.T. S.I.P.B. make no representations about the suitability of
|
||||
* this software for any purpose. It is provided "as is" without
|
||||
* express or implied warranty.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "com_err.h"
|
||||
#include "error_table.h"
|
||||
#include "internal.h"
|
||||
|
||||
static const char char_set[] =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";
|
||||
|
||||
static char buf[6];
|
||||
|
||||
const char * error_table_name(errcode_t num)
|
||||
{
|
||||
int ch;
|
||||
int i;
|
||||
char *p;
|
||||
|
||||
/* num = aa aaa abb bbb bcc ccc cdd ddd d?? ??? ??? */
|
||||
p = buf;
|
||||
num >>= ERRCODE_RANGE;
|
||||
/* num = ?? ??? ??? aaa aaa bbb bbb ccc ccc ddd ddd */
|
||||
num &= 077777777L;
|
||||
/* num = 00 000 000 aaa aaa bbb bbb ccc ccc ddd ddd */
|
||||
for (i = 4; i >= 0; i--) {
|
||||
ch = (int)((num >> BITS_PER_CHAR * i) & ((1 << BITS_PER_CHAR) - 1));
|
||||
if (ch != 0)
|
||||
*p++ = char_set[ch-1];
|
||||
}
|
||||
*p = '\0';
|
||||
return(buf);
|
||||
}
|
||||
53
e2fsprogs/lib/et/init_et.c
Normal file
53
e2fsprogs/lib/et/init_et.c
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* $Header$
|
||||
* $Source$
|
||||
* $Locker$
|
||||
*
|
||||
* Copyright 1986, 1987, 1988 by MIT Information Systems and
|
||||
* the MIT Student Information Processing Board.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software and
|
||||
* its documentation for any purpose is hereby granted, provided that
|
||||
* the names of M.I.T. and the M.I.T. S.I.P.B. not be used in
|
||||
* advertising or publicity pertaining to distribution of the software
|
||||
* without specific, written prior permission. M.I.T. and the
|
||||
* M.I.T. S.I.P.B. make no representations about the suitability of
|
||||
* this software for any purpose. It is provided "as is" without
|
||||
* express or implied warranty.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#ifdef HAVE_STDLIB_H
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#include "com_err.h"
|
||||
#include "error_table.h"
|
||||
|
||||
struct foobar {
|
||||
struct et_list etl;
|
||||
struct error_table et;
|
||||
};
|
||||
|
||||
extern struct et_list * _et_dynamic_list;
|
||||
|
||||
int init_error_table(const char * const *msgs, long base, int count)
|
||||
{
|
||||
struct foobar * new_et;
|
||||
|
||||
if (!base || !count || !msgs)
|
||||
return 0;
|
||||
|
||||
new_et = (struct foobar *) malloc(sizeof(struct foobar));
|
||||
if (!new_et)
|
||||
return ENOMEM; /* oops */
|
||||
new_et->etl.table = &new_et->et;
|
||||
new_et->et.msgs = msgs;
|
||||
new_et->et.base = base;
|
||||
new_et->et.n_msgs= count;
|
||||
|
||||
new_et->etl.next = _et_dynamic_list;
|
||||
_et_dynamic_list = &new_et->etl;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user