print-copyr.c 2.0 KB

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