]> Dogcows Code - chaz/tar/blob - lib/print-copyr.c
Initial revision
[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 #if HAVE_ICONV
25 # include <iconv.h>
26
27 # if HAVE_STDLIB_H
28 # include <stdlib.h>
29 # endif
30 #endif
31
32 #include "copysym.h"
33
34 /* Store into BUF (of size BUFSIZE) a representation of the copyright
35 symbol (C-in-a-circle) that is a valid text string for the current
36 locale. Return BUF if successful, and a pointer to some other
37 string otherwise. */
38
39 char const *
40 copyright_symbol (char *buf, size_t bufsize)
41 {
42 #if HAVE_ICONV
43 char const *outcharset = getenv ("OUTPUT_CHARSET");
44
45 if (! (outcharset && *outcharset))
46 {
47 extern char const *locale_charset (void);
48 outcharset = locale_charset ();
49 }
50
51 if (*outcharset)
52 {
53 iconv_t conv = iconv_open (outcharset, "UTF-8");
54
55 if (conv != (iconv_t) -1)
56 {
57 static char const copyright_utf_8[] = "\302\251";
58 char ICONV_CONST *inptr = (char ICONV_CONST *) &copyright_utf_8;
59 size_t inleft = sizeof copyright_utf_8;
60 char *outptr = buf;
61 size_t chars = iconv (conv, &inptr, &inleft, &outptr, &bufsize);
62
63 iconv_close (conv);
64
65 if (chars != (size_t) -1)
66 return buf;
67 }
68 }
69 #endif
70
71 /* "(C)" is the best we can do in ASCII. */
72 return "(C)";
73 }
This page took 0.038682 seconds and 4 git commands to generate.