[14063] | 1 | /* Copyright 1988, 1998 by the Massachusetts Institute of Technology. |
---|
| 2 | * |
---|
| 3 | * Permission to use, copy, modify, and distribute this |
---|
| 4 | * software and its documentation for any purpose and without |
---|
| 5 | * fee is hereby granted, provided that the above copyright |
---|
| 6 | * notice appear in all copies and that both that copyright |
---|
| 7 | * notice and this permission notice appear in supporting |
---|
| 8 | * documentation, and that the name of M.I.T. not be used in |
---|
| 9 | * advertising or publicity pertaining to distribution of the |
---|
| 10 | * software without specific, written prior permission. |
---|
| 11 | * M.I.T. makes no representations about the suitability of |
---|
| 12 | * this software for any purpose. It is provided "as is" |
---|
| 13 | * without express or implied warranty. |
---|
| 14 | */ |
---|
| 15 | |
---|
| 16 | static const char rcsid[] = "$Id: get_fallback_file.c,v 1.1 1999-12-08 22:06:44 danw Exp $"; |
---|
| 17 | |
---|
| 18 | #include "globalmessage.h" |
---|
| 19 | #include <sys/types.h> |
---|
| 20 | |
---|
| 21 | Code_t get_fallback_file(char **ret_data, int *ret_size, |
---|
| 22 | char *message_filename) |
---|
| 23 | { |
---|
| 24 | char *message_data; |
---|
| 25 | int message_filedesc; |
---|
| 26 | int message_size; |
---|
| 27 | int readstat; |
---|
| 28 | |
---|
| 29 | /* guard against NULL arguments */ |
---|
| 30 | if((!ret_data)||(!ret_size)||(!message_filename)) { |
---|
| 31 | return(GMS_NULL_ARG_ERR); |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | /* the return time stamp and version stuff is saved with the local |
---|
| 35 | * anyway... |
---|
| 36 | */ |
---|
| 37 | message_filedesc = open(message_filename, O_RDONLY, 0); |
---|
| 38 | |
---|
| 39 | if(message_filedesc == -1) { |
---|
| 40 | /* handle open failure, use unix errors */ |
---|
| 41 | return(errno); |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | readstat = read_to_memory(&message_data, &message_size, message_filedesc); |
---|
| 45 | close(message_filedesc); /* regardless of errors */ |
---|
| 46 | |
---|
| 47 | if(readstat) { |
---|
| 48 | /* handle read_to_memory errors, clean up timestamp */ |
---|
| 49 | return(readstat); |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | *ret_data = message_data; |
---|
| 53 | *ret_size = message_size; |
---|
| 54 | return(0); |
---|
| 55 | } |
---|