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.transition;
21 
22 public import ocean.sys.linux.linux;
23 alias ocean.sys.linux.linux posix;
24 
25 /*******************************************************************************
26 
27         Stuff for sysErrorMsg(), kindly provided by Regan Heath.
28 
29 *******************************************************************************/
30 
31 import core.stdc.errno;
32 import core.stdc.string;
33 
34 
35 /*******************************************************************************
36 
37 *******************************************************************************/
38 
39 struct SysError
40 {
41         /***********************************************************************
42 
43         ***********************************************************************/
44 
45         static uint lastCode ()
46         {
47              return errno;
48         }
49 
50         /***********************************************************************
51 
52         ***********************************************************************/
53 
54         static istring lastMsg ()
55         {
56                 return lookup (lastCode);
57         }
58 
59         /***********************************************************************
60 
61         ***********************************************************************/
62 
63         static istring lookup (uint errcode)
64         {
65                 char[] text;
66 
67                 size_t  r;
68                 char* pemsg;
69 
70                 pemsg = strerror(errcode);
71                 r = strlen(pemsg);
72 
73                 /* Remove \r\n from error string */
74                 if (pemsg[r-1] == '\n') r--;
75                 if (pemsg[r-1] == '\r') r--;
76                 text = pemsg[0..r].dup;
77 
78                 return assumeUnique(text);
79         }
80 }