~ubuntu-branches/ubuntu/karmic/libmtp/karmic

« back to all changes in this revision

Viewing changes to examples/util.c

  • Committer: Bazaar Package Importer
  • Author(s): Savvas Radevic, Savvas Radevic, Flávio Martins
  • Date: 2009-04-18 19:58:14 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20090418195814-lbizx2w4c0mgknc8
Tags: 0.3.7-3ubuntu1
[ Savvas Radevic ]
* Merge from debian unstable, remaining changes:
  + debian/control: Add Breaks to ensure the right udev version gets used.
  + debian/libmtp.install.in, debian/libmtp.preinst.in, 
    debian/libmtp.postinst.in: Clean up the mess where files were still 
    going into the wrong directory.
* debian/libmtp.preinst.in: Dropped check on unsupported 0.2.5-1 (hardy has 
  0.2.6.1-2ubuntu1)

[ Flávio Martins ]
* debian/rules: Append proper prefix 45- to libmtp rules in UDEV variable
* debian/libmtp.install.in: ../../45-libmtp@SOVERSION@.rules lib/udev/rules.d

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/** 
 
2
 * \file util.c
 
3
 * A set of common utility functions found
 
4
 * in all samples.
 
5
 *
 
6
 * Copyright (C) 2008 Linus Walleij <triad@df.lth.se>
 
7
 *
 
8
 * This library is free software; you can redistribute it and/or
 
9
 * modify it under the terms of the GNU Lesser General Public
 
10
 * License as published by the Free Software Foundation; either
 
11
 * version 2 of the License, or (at your option) any later version.
 
12
 *
 
13
 * This library is distributed in the hope that it will be useful,
 
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
16
 * Lesser General Public License for more details.
 
17
 *
 
18
 * You should have received a copy of the GNU Lesser General Public
 
19
 * License along with this library; if not, write to the
 
20
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
21
 * Boston, MA 02111-1307, USA.
 
22
 */
 
23
#include "util.h"
 
24
#ifdef HAVE_LANGINFO_H
 
25
#include <langinfo.h>
 
26
#endif
 
27
#ifdef HAVE_LOCALE_H
 
28
#include <locale.h>
 
29
#endif
 
30
#include <stdlib.h>
 
31
#include <stdio.h>
 
32
#include <string.h>
 
33
 
 
34
void checklang(void)
 
35
{
 
36
  char *langsuff = NULL;
 
37
  char *lang = getenv("LANG");
 
38
 
 
39
#ifdef HAVE_LOCALE_H
 
40
  // Set the locale in accordance with environment
 
41
  setlocale(LC_ALL, "");
 
42
#endif
 
43
#ifdef HAVE_LANGINFO_H
 
44
  langsuff = nl_langinfo(CODESET);
 
45
#else
 
46
  /*
 
47
   * Check environment variables $LANG and $LC_CTYPE
 
48
   * to see if we want to support UTF-8 unicode
 
49
   */
 
50
  if (lang != NULL) {
 
51
    if (strlen(lang) > 5) {
 
52
      langsuff = &lang[strlen(lang)-5];
 
53
    }
 
54
  }
 
55
#endif
 
56
  if (langsuff == NULL) {
 
57
    printf("Could not determine language suffix for your system. Please check your setup!\n");
 
58
  } else if (strcmp(langsuff, "UTF-8")) {
 
59
    printf("Your system does not appear to have UTF-8 enabled ($LANG=\"%s\")\n", lang);
 
60
    printf("If you want to have support for diacritics and Unicode characters,\n");
 
61
    printf("please switch your locale to an UTF-8 locale, e.g. \"en_US.UTF-8\".\n");
 
62
  }
 
63
}