Thread: writing newlines to stdout file descriptor

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,735

    writing newlines to stdout file descriptor

    I get this:
    Code:
    ...
    pawPrintf( "%u", 10 ) gave:
    10pawPrintf( "%d, %s", did, "abc" ) gave:
    2, abc
    ...
    From this:
    Code:
    pawd test_Printf()
    {
    #define PRINTF( ARGS, ... ) \
    	do \
    	{ \
    		puts( "pawPrintf( " #ARGS ", " #__VA_ARGS__ " ); gave:" ); \
    		did = pawPrintf( ARGS "\n", __VA_ARGS__ ); \
    	} \
    	while(0)
    	pawd did;
    	puts("Attempting pawPrintf...\n");
    	PRINTF( "%u", 10 );
    	if ( did < 0 )
    		return -1;
    	PRINTF( "%d, %s", did, "abc" );
    	return -(did < 0);
    #undef PRINTF
    }
    Because I don't want my library to rely on CRT (and all the problems it comes with) I'm trying to remove reliance on standard C libraries (with exceptions for things like limits.h), I'm starting off with the file descriptors since they're the native format for linux/unix/osx which makes it convenient for me to test the wrapper functions work correctly. I've tried all I can think of but I still haven't been able to get the newline character to print, or at least produce the expected output, anyone have any familiarity with this, or any ideas to try?

    Edit: For reference the internal calls fob things down to here:
    Code:
    PAW_API pawzd pawFdPrintv( PAWFD fd, void *inf, paws args, va_list va )
    {
    	PAWS STR = {{0}};
    	pawzd did = pawInitStringv( &STR, args, va );
    	if ( did >= 0 )
    	{
    		paws str = pawSeekBufferHead( &STR );
    		did = pawFdPrint( fd, inf, str, did );
    		pawTermString( &STR );
    	}
    	return did;
    }
    I used PAWFD since I need the type name to be consistent across systems, on windows it's HANDLE instead of int, the final functions ares these:
    Code:
    PAW_API pawzd	pawFdPrint( PAWFD fd, PAWOPS *ops, void const *src, pawzd cap )
    {
    	(void)ops;
    	if ( cap >= 0 )
    		return write( fd, src, cap );
    	return -1;
    }
    PAW_API pawzd	pawFdParse( PAWFD fd, PAWOPS *ops, void *dst, pawzd cap )
    {
    	(void)ops;
    	if ( cap >= 0 )
    		return read( fd, dst, cap );
    	return -1;
    }
    PAW_API void	pawFdFlush( PAWFD fd ) { fsync(fd); }
    Don't have anything for opening & closing yet, figured I'd first make sure I can output correctly before focusing on extras

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. reading and writing to stdin, stdout and file
    By Quinhagen in forum C Programming
    Replies: 2
    Last Post: 05-25-2016, 07:39 AM
  2. Replies: 6
    Last Post: 11-30-2011, 12:49 AM
  3. How to read the file descriptor
    By vin_pll in forum C++ Programming
    Replies: 2
    Last Post: 11-26-2007, 01:58 AM
  4. writing stdout to a file
    By SIKCAR in forum C Programming
    Replies: 4
    Last Post: 09-09-2002, 06:35 AM
  5. newlines from read file :(
    By loobian in forum C++ Programming
    Replies: 12
    Last Post: 10-15-2001, 03:20 PM

Tags for this Thread