]> Dogcows Code - chaz/tar/blob - lib/print-copyr.c
Include stddef.h, for size_t.
[chaz/tar] / lib / print-copyr.c
1 /* copysym.c -- Return a copyright symbol suitable for the current locale.
2 Copyright (C) 2001 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software Foundation,
16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
17
18 /* Written by Paul Eggert. */
19
20 #if HAVE_CONFIG_H
21 # include <config.h>
22 #endif
23
24 #include <stddef.h>
25
26 #if HAVE_ICONV
27 # include <iconv.h>
28
29 # if ! USE_INCLUDED_LIBINTL && HAVE_LANGINFO_CODESET
30 # include <langinfo.h>
31 # endif
32
33 # if HAVE_STDLIB_H
34 # include <stdlib.h>
35 # endif
36 #endif
37
38 #include "copysym.h"
39
40 /* Store into BUF (of size BUFSIZE) a representation of the copyright
41 symbol (C-in-a-circle) that is a valid text string for the current
42 locale. Return BUF if successful, and a pointer to some other
43 string otherwise. */
44
45 char const *
46 copyright_symbol (char *buf, size_t bufsize)
47 {
48 #if HAVE_ICONV
49 char const *outcharset = getenv ("OUTPUT_CHARSET");
50
51 if (! (outcharset && *outcharset))
52 {
53 #if USE_INCLUDED_LIBINTL
54 extern char const *locale_charset (void);
55 outcharset = locale_charset ();
56 #else
57 # if HAVE_LANGINFO_CODESET
58 outcharset = nl_langinfo (CODESET);
59 # endif
60 #endif
61 }
62
63 if (*outcharset)
64 {
65 iconv_t conv = iconv_open (outcharset, "UTF-8");
66
67 if (conv != (iconv_t) -1)
68 {
69 static char const copyright_utf_8[] = "\302\251";
70 char ICONV_CONST *inptr = (char ICONV_CONST *) &copyright_utf_8;
71 size_t inleft = sizeof copyright_utf_8;
72 char *outptr = buf;
73 size_t chars = iconv (conv, &inptr, &inleft, &outptr, &bufsize);
74
75 iconv_close (conv);
76
77 if (chars != (size_t) -1)
78 return buf;
79 }
80 }
81 #endif
82
83 /* "(C)" is the best we can do in ASCII. */
84 return "(C)";
85 }
This page took 0.037183 seconds and 5 git commands to generate.