File tree Expand file tree Collapse file tree 4 files changed +78
-1
lines changed Expand file tree Collapse file tree 4 files changed +78
-1
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ FRONTEND_DEBUG = $(FRONTEND)-debug
3
3
4
4
BASE = src/
5
5
6
- SRC_DIR = . prep parse sema global parse/stmt sema/stmt sema/pass
6
+ SRC_DIR = . util prep parse sema global parse/stmt sema/stmt sema/pass
7
7
SRC_DIR_BASE = $(addprefix $(BASE ) ,$(SRC_DIR ) )
8
8
9
9
GCC_VER_MAJ = $(shell $(CC ) -dumpversion | cut -f 1 -d '.')
Original file line number Diff line number Diff line change
1
+ /* Copyright 2017 Codethink Ltd.
2
+ *
3
+ * Licensed under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License.
5
+ * You may obtain a copy of the License at
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+
16
+ #ifndef __ofc_dprintf_h__
17
+ #define __ofc_dprintf_h__
18
+
19
+ #include <stdio.h>
20
+
21
+ #if defined(_GNU_SOURCE ) || (_XOPEN_SOURCE >= 700 ) || (_POSIX_C_SOURCE >= 200809L )
22
+ #define NATIVE_DPRINTF
23
+ #endif
24
+
25
+ #ifndef NATIVE_DPRINTF
26
+ int dprintf (int fd , const char * format , ...)
27
+ __attribute__ ((format (printf , 2 , 3 )));
28
+ #endif
29
+
30
+ #endif
Original file line number Diff line number Diff line change 19
19
#include <ctype.h>
20
20
21
21
#include "ofc/colstr.h"
22
+ #include "ofc/util/dprintf.h"
22
23
23
24
24
25
struct ofc_colstr_s
Original file line number Diff line number Diff line change
1
+ /* Copyright 2017 Codethink Ltd.
2
+ *
3
+ * Licensed under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License.
5
+ * You may obtain a copy of the License at
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+
16
+ #include "ofc/util/dprintf.h"
17
+ #include <stdarg.h>
18
+ #include <unistd.h>
19
+
20
+ #ifndef NATIVE_DPRINTF
21
+ int dprintf (int fd , const char * format , ...)
22
+ {
23
+ va_list args ;
24
+ va_start (args , format );
25
+
26
+ va_list largs ;
27
+ va_copy (largs , args );
28
+ int len = vsnprintf (NULL , 0 , format , largs );
29
+ va_end (largs );
30
+
31
+ if (len <= 0 )
32
+ {
33
+ va_end (args );
34
+ return len ;
35
+ }
36
+
37
+ char buff [len + 1 ];
38
+ int plen = vsnprintf (buff , (len + 1 ), format , args );
39
+ va_end (args );
40
+
41
+ if (len != plen )
42
+ return -1 ;
43
+
44
+ return (int )write (fd , buff , len );
45
+ }
46
+ #endif
You can’t perform that action at this time.
0 commit comments