2
* Copyright (C) 2007-2009 Jordi Mas i Hernàndez <jmas@softcatala.org>
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License as
6
* published by the Free Software Foundation; either version 2 of the
7
* License, or (at your option) any later version.
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 GNU
12
* General Public License for more details.
14
* You should have received a copy of the GNU General Public
15
* License along with this program; if not, write to the
16
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17
* Boston, MA 02111-1307, USA.
21
using System.Runtime.InteropServices;
23
using System.Globalization;
24
using System.Threading;
29
static public class Unix
32
static extern IntPtr localeconv ();
34
[DllImport ("libc")] // Linux
35
static extern int prctl (int option, byte [] arg2, IntPtr arg3, IntPtr arg4, IntPtr arg5);
37
[DllImport ("libc")] // BSD
38
static extern void setproctitle (byte [] fmt, byte [] str_arg);
41
/* Taken from locale.h */
42
[StructLayout (LayoutKind.Sequential)]
45
public string decimal_point;
46
public string thousands_sep;
47
public string grouping;
48
public string int_curr_symbol;
49
public string currency_symbol;
50
public string mon_decimal_point;
51
public string mon_thousands_sep;
52
public string mon_grouping;
53
public string positive_sign;
54
public string negative_sign;
63
char int_p_cs_precedes;
64
char int_p_sep_by_space;
65
char int_n_cs_precedes;
66
char int_n_sep_by_space;
71
// Mono supports less locales that Unix systems
72
// To overcome this limitation we setup the right locale parameters
73
// when the Mono locale is InvariantCulture, that is, when the user's locale
74
// has not been identified and the default Mono locale is used
76
// See: https://bugzilla.novell.com/show_bug.cgi?id=420468
78
static public void FixLocaleInfo ()
80
IntPtr st = IntPtr.Zero;
82
int platform = (int) Environment.OSVersion.Platform;
84
if (platform != 4 && platform != 128) // Only in Unix based systems
87
if (CultureInfo.CurrentCulture != CultureInfo.InvariantCulture) // Culture well supported
92
if (st == IntPtr.Zero) return;
94
lv = (lconv) Marshal.PtrToStructure (st, typeof (lconv));
95
CultureInfo culture = (CultureInfo) CultureInfo.CurrentCulture.Clone ();
96
culture.NumberFormat.NumberDecimalSeparator = lv.decimal_point;
97
Thread.CurrentThread.CurrentCulture = culture;
102
public static void SetProcessName (string name)
104
int platform = (int) Environment.OSVersion.Platform;
105
if (platform != 4 && platform != 128)
109
if (prctl (15 /* PR_SET_NAME */, Encoding.ASCII.GetBytes (name + "\0"),
110
IntPtr.Zero, IntPtr.Zero, IntPtr.Zero) != 0) {
111
throw new ApplicationException ("Error setting process name: " +
112
Mono.Unix.Native.Stdlib.GetLastError ());
114
} catch (EntryPointNotFoundException) {
115
setproctitle (Encoding.ASCII.GetBytes ("%s\0"),
116
Encoding.ASCII.GetBytes (name + "\0"));