//-----------------------------------------------------------------------------
// Copyright © 2006 - Philip Howard - All rights reserved
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//-----------------------------------------------------------------------------
// package	libh/io
// homepage	http://libh.slashusr.org/
//-----------------------------------------------------------------------------
// author	Philip Howard
// email	libh at ipal dot org
// homepage	http://phil.ipal.org/
//-----------------------------------------------------------------------------
// This file is best viewed using a fixed spaced font such as Courier
// and in a display at least 120 columns wide.
//-----------------------------------------------------------------------------

#include "io_lib.h"

#include <stdio.h>
#include <unistd.h>

__FMACRO_BEGIN__
//-----------------------------------------------------------------------------
// macro	eput_cwd
//
// purpose	Output the current directory string to stderr.
//
// arguments	-none-
//
// returns	(size_t) length of string written
//-----------------------------------------------------------------------------
#define eput_cwd() (fput_cwd((stderr)))

__FMACRO_END__

__FMACRO_BEGIN__
//-----------------------------------------------------------------------------
// macro	put_cwd
//
// purpose	Output the current directory string to stdout.
//
// arguments	-none-
//
// returns	(size_t) length of string written
//-----------------------------------------------------------------------------
#define put_cwd() (fput_cwd((stdout)))

__FMACRO_END__

__PROTO_BEGIN__
//-----------------------------------------------------------------------------
// function	fput_cwd
//
// purpose	Output the current directory string to the specified file.
//
// arguments	1 (FILE *) which file to write to, or NULL for stdout
//
// returns	(size_t) length of string written
//-----------------------------------------------------------------------------
int
fput_cwd (
    FILE *		arg_file
    )
__PROTO_END__
{
    char		cwd_space	[ PATH_MAX + 1 ];

    if ( ! getcwd( cwd_space, sizeof cwd_space ) ) return 0;
    if ( ! arg_file ) arg_file = stdout;
    fputs( cwd_space, arg_file );
    return strlen( cwd_space );
}

