source: libcfa/src/bits/debug.cfa @ fe63ae6

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

remove extern "C" from include files protected in CFA stdhdr directory

  • 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
[c1ee231]12// Last Modified On : Wed Jun 17 11:07:13 2020
13// Update Count     : 12
[9d944b2]14//
15
16#include <stdio.h>
17#include <stdlib.h>
18#include <string.h>
19#include <errno.h>
20#include <stdarg.h>
21#include <unistd.h>
22
[ec72861]23enum { buffer_size = 4096 };
[9d944b2]24static char buffer[ buffer_size ];
25
26extern "C" {
[e3fea42]27        void __cfaabi_bits_write( int fd, const char in_buffer[], int len ) {
[9d944b2]28                // ensure all data is written
[6a5be52]29                for ( int count = 0, retcode; count < len; count += retcode ) {
[9d944b2]30                        in_buffer += count;
31
32                        for ( ;; ) {
[1c40091]33                                retcode = write( fd, in_buffer, len - count );
[9d944b2]34
35                                // not a timer interrupt ?
[6a5be52]36                                if ( retcode != -1 || errno != EINTR ) break;
[9d944b2]37                        }
38
39                        if ( retcode == -1 ) _exit( EXIT_FAILURE );
40                }
41        }
42
[1c40091]43        void __cfaabi_bits_acquire() __attribute__((__weak__)) {}
44        void __cfaabi_bits_release() __attribute__((__weak__)) {}
[9d944b2]45
[1c40091]46        void __cfaabi_bits_print_safe  ( int fd, const char fmt[], ... ) __attribute__(( format(printf, 2, 3) )) {
[9d944b2]47                va_list args;
48
49                va_start( args, fmt );
[1c40091]50                __cfaabi_bits_acquire();
[6a5be52]51
[9d944b2]52                int len = vsnprintf( buffer, buffer_size, fmt, args );
[1c40091]53                __cfaabi_bits_write( fd, buffer, len );
[9d944b2]54
[1c40091]55                __cfaabi_bits_release();
[9d944b2]56                va_end( args );
57        }
58
[1c40091]59        void __cfaabi_bits_print_nolock( int fd, const char fmt[], ... ) __attribute__(( format(printf, 2, 3) )) {
[9d944b2]60                va_list args;
61
62                va_start( args, fmt );
[6a5be52]63
[9d944b2]64                int len = vsnprintf( buffer, buffer_size, fmt, args );
[1c40091]65                __cfaabi_bits_write( fd, buffer, len );
[9d944b2]66
67                va_end( args );
68        }
69
[1c40091]70        void __cfaabi_bits_print_vararg( int fd, const char fmt[], va_list args ) {
[9d944b2]71                int len = vsnprintf( buffer, buffer_size, fmt, args );
[1c40091]72                __cfaabi_bits_write( fd, buffer, len );
[9d944b2]73        }
74
[1c40091]75        void __cfaabi_bits_print_buffer( int fd, char in_buffer[], int in_buffer_size, const char fmt[], ... ) __attribute__(( format(printf, 4, 5) )) {
[9d944b2]76                va_list args;
77
78                va_start( args, fmt );
[6a5be52]79
[9d944b2]80                int len = vsnprintf( in_buffer, in_buffer_size, fmt, args );
[1c40091]81                __cfaabi_bits_write( fd, in_buffer, len );
[9d944b2]82
83                va_end( args );
84        }
[169d944]85}
Note: See TracBrowser for help on using the repository browser.