Open64 (mfef90, whirl2f, and IR tools)  TAG: version-openad; SVN changeset: 916
catgetmsg.c
Go to the documentation of this file.
00001 #pragma ident "@(#)92/msgnew/catgetmsg.c        92.2    06/03/99 09:59:18"
00002 
00003 /*
00004 
00005   Copyright (C) 2000, 2001 Silicon Graphics, Inc.  All Rights Reserved.
00006 
00007   This program is free software; you can redistribute it and/or modify it
00008   under the terms of version 2 of the GNU General Public License as
00009   published by the Free Software Foundation.
00010 
00011   This program is distributed in the hope that it would be useful, but
00012   WITHOUT ANY WARRANTY; without even the implied warranty of
00013   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
00014 
00015   Further, this software is distributed without any warranty that it is
00016   free of the rightful claim of any third person regarding infringement 
00017   or the like.  Any license provided herein, whether implied or 
00018   otherwise, applies only to this software file.  Patent licenses, if 
00019   any, provided herein do not apply to combinations of this program with 
00020   other software, or any other product whatsoever.  
00021 
00022   You should have received a copy of the GNU General Public License along
00023   with this program; if not, write the Free Software Foundation, Inc., 59
00024   Temple Place - Suite 330, Boston MA 02111-1307, USA.
00025 
00026   Contact information:  Silicon Graphics, Inc., 1600 Amphitheatre Pky,
00027   Mountain View, CA 94043, or:
00028 
00029   http://www.sgi.com
00030 
00031   For further information regarding this notice, see:
00032 
00033   http://oss.sgi.com/projects/GenInfo/NoticeExplan
00034 
00035 */
00036 
00037 
00038 #if defined(__STDC__) && defined(_LITTLE_ENDIAN)
00039         #pragma weak _catgetmsg = catgetmsg
00040 #else                           /* else STDC and _LITTLE_ENDIAN */
00041 #if defined(__STDC__) && !defined(_LIBU)
00042         #pragma weak catgetmsg = _catgetmsg
00043         #pragma weak __catgetmsg_error_code = ___catgetmsg_error_code
00044 #endif
00045 #endif                          /* end STDC and _LITTLE_ENDIAN */
00046 
00047 /*
00048  * IMPORTANT:
00049  * This section is needed since this file also resides in the compilers'
00050  * libcsup/msg (v7.2 and higher). Once the compilers drop support for
00051  * pre-IRIX 6.5 releases this can be removed. Please build a libu before
00052  * checking in any changes to this file.
00053  *
00054  */
00055 
00056 #define DISABLE_NL_TYPES_SYMBOL_RENAMING 1 /* for our <nl_types.h> */
00057 #define catgets my_catgets /* hack to refer to our own catgets() */
00058 
00059 #ifdef  _LITTLE_ENDIAN
00060 #include <nl_types.h>
00061 #include <cray/nlcatmsg.h>
00062 #include <string.h>
00063 #else                           /* Else _LITTLE_ENDIAN */
00064 #ifndef _LIBU
00065 #include "synonyms.h"
00066 #endif
00067 
00068 #define __NLS_INTERNALS 1
00069 #include <nl_types.h>
00070 #undef __NLS_INTERNALS
00071 #include <string.h>
00072 #endif                          /* End _LITTLE_ENDIAN */
00073 
00074 
00075 /*
00076  * catgetmsg -- retrieves a message to a user supplied buffer from a catalog
00077  *
00078  */
00079 char *
00080 catgetmsg(
00081           nl_catd catd,
00082           int set_num,
00083           int msg_num,
00084           char *buf,
00085           int buflen
00086           )
00087 {
00088   size_t len;
00089   char *str;
00090   
00091   if ((str = catgets(catd, set_num, msg_num, NULL)) != NULL) {
00092     
00093     /* find the proper string length to copy */
00094     len = strlen(str); 
00095     if (len >= buflen)
00096       len = buflen - 1;
00097     
00098     (void) strncpy(buf, str, len);
00099     buf[len] = '\0';
00100     
00101     return buf;
00102   } else {
00103     return "\0";
00104   }
00105 }
00106 
00107 
00108 #ifndef _LITTLE_ENDIAN
00109 /*
00110  *      __catgetmsg_error_code - returns the error status from the last
00111  *              failed catgetmsg() call.
00112  *
00113  *              returns  < 0    Internal error code
00114  *                       > 0    System error code
00115  */
00116 int
00117 __catgetmsg_error_code(void)
00118 {
00119 
00120 /* Solaris workaround
00121  * __catgets_error_code is only defined on IRIX nl_types.h,
00122  * remove this call to avoid linker error.
00123  */
00124   return 1;
00125 }
00126 #endif                          /* End NOT _LITTLE_ENDIAN */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines