source: libcfa/src/bits/debug.cfa @ 87e0b015

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 87e0b015 was e3fea42, checked in by Peter A. Buhr <pabuhr@…>, 5 years ago

change "const char *" to "const char []"

  • Property mode set to 100644
File size: 2.2 KB
RevLine 
[9d944b2]1//
2// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
[c2b9f21]7// debug.c --
[9d944b2]8//
9// Author           : Thierry Delisle
10// Created On       : Thu Mar 30 12:30:01 2017
[ec72861]11// Last Modified By : Peter A. Buhr
[e3fea42]12// Last Modified On : Tue Feb  4 13:03:16 2020
13// Update Count     : 11
[9d944b2]14//
15
16extern "C" {
17#include <stdio.h>
18#include <stdlib.h>
19#include <string.h>
20#include <errno.h>
21#include <stdarg.h>
22#include <unistd.h>
23}
24
[ec72861]25enum { buffer_size = 4096 };
[9d944b2]26static char buffer[ buffer_size ];
27
28extern "C" {
[e3fea42]29        void __cfaabi_bits_write( int fd, const char in_buffer[], int len ) {
[9d944b2]30                // ensure all data is written
[6a5be52]31                for ( int count = 0, retcode; count < len; count += retcode ) {
[9d944b2]32                        in_buffer += count;
33
34                        for ( ;; ) {
[1c40091]35                                retcode = write( fd, in_buffer, len - count );
[9d944b2]36
37                                // not a timer interrupt ?
[6a5be52]38                                if ( retcode != -1 || errno != EINTR ) break;
[9d944b2]39                        }
40
41                        if ( retcode == -1 ) _exit( EXIT_FAILURE );
42                }
43        }
44
[1c40091]45        void __cfaabi_bits_acquire() __attribute__((__weak__)) {}
46        void __cfaabi_bits_release() __attribute__((__weak__)) {}
[9d944b2]47
[1c40091]48        void __cfaabi_bits_print_safe  ( int fd, const char fmt[], ... ) __attribute__(( format(printf, 2, 3) )) {
[9d944b2]49                va_list args;
50
51                va_start( args, fmt );
[1c40091]52                __cfaabi_bits_acquire();
[6a5be52]53
[9d944b2]54                int len = vsnprintf( buffer, buffer_size, fmt, args );
[1c40091]55                __cfaabi_bits_write( fd, buffer, len );
[9d944b2]56
[1c40091]57                __cfaabi_bits_release();
[9d944b2]58                va_end( args );
59        }
60
[1c40091]61        void __cfaabi_bits_print_nolock( int fd, const char fmt[], ... ) __attribute__(( format(printf, 2, 3) )) {
[9d944b2]62                va_list args;
63
64                va_start( args, fmt );
[6a5be52]65
[9d944b2]66                int len = vsnprintf( buffer, buffer_size, fmt, args );
[1c40091]67                __cfaabi_bits_write( fd, buffer, len );
[9d944b2]68
69                va_end( args );
70        }
71
[1c40091]72        void __cfaabi_bits_print_vararg( int fd, const char fmt[], va_list args ) {
[9d944b2]73                int len = vsnprintf( buffer, buffer_size, fmt, args );
[1c40091]74                __cfaabi_bits_write( fd, buffer, len );
[9d944b2]75        }
76
[1c40091]77        void __cfaabi_bits_print_buffer( int fd, char in_buffer[], int in_buffer_size, const char fmt[], ... ) __attribute__(( format(printf, 4, 5) )) {
[9d944b2]78                va_list args;
79
80                va_start( args, fmt );
[6a5be52]81
[9d944b2]82                int len = vsnprintf( in_buffer, in_buffer_size, fmt, args );
[1c40091]83                __cfaabi_bits_write( fd, in_buffer, len );
[9d944b2]84
85                va_end( args );
86        }
[169d944]87}
Note: See TracBrowser for help on using the repository browser.