1 /*******************************************************************************
2 
3         Copyright:
4             Copyright (c) 2004 Kris Bell.
5             Some parts copyright (c) 2009-2016 dunnhumby Germany GmbH.
6             All rights reserved.
7 
8         License:
9             Tango Dual License: 3-Clause BSD License / Academic Free License v3.0.
10             See LICENSE_TANGO.txt for details.
11 
12         Version: Initial release: November 2005
13 
14         Authors: Kris
15 
16 *******************************************************************************/
17 
18 module ocean.sys.Common;
19 
20 import ocean.core.TypeConvert : assumeUnique;
21 import ocean.meta.types.Qualifiers;
22 
23 public import ocean.sys.linux.linux;
24 alias ocean.sys.linux.linux posix;
25 
26 /*******************************************************************************
27 
28         Stuff for sysErrorMsg(), kindly provided by Regan Heath.
29 
30 *******************************************************************************/
31 
32 import core.stdc.errno;
33 import core.stdc.string;
34 
35 
36 /*******************************************************************************
37 
38 *******************************************************************************/
39 
40 struct SysError
41 {
42         /***********************************************************************
43 
44         ***********************************************************************/
45 
46         static uint lastCode ()
47         {
48              return errno;
49         }
50 
51         /***********************************************************************
52 
53         ***********************************************************************/
54 
55         static istring lastMsg ()
56         {
57                 return lookup (lastCode);
58         }
59 
60         /***********************************************************************
61 
62         ***********************************************************************/
63 
64         static istring lookup (uint errcode)
65         {
66                 char[] text;
67 
68                 size_t  r;
69                 char* pemsg;
70 
71                 pemsg = strerror(errcode);
72                 r = strlen(pemsg);
73 
74                 /* Remove \r\n from error string */
75                 if (pemsg[r-1] == '\n') r--;
76                 if (pemsg[r-1] == '\r') r--;
77                 text = pemsg[0..r].dup;
78 
79                 return assumeUnique(text);
80         }
81 }