1%% options 2 3copyright owner = Dirk Krause 4copyright year = 2015-xxxx 5SPDX-License-Identifier: BSD-3-Clause 6 7 8 9%% header 10 11/** @file dk4getcwdd.h Get current working directoy in dkChar. 12*/ 13 14#ifndef DK4CONF_H_INCLUDED 15#if DK4_BUILDING_DKTOOLS4 16#include "dk4conf.h" 17#else 18#include <dktools-4/dk4conf.h> 19#endif 20#endif 21 22#ifndef DK4ERROR_H_INCLUDED 23#if DK4_BUILDING_DKTOOLS4 24#include <libdk4base/dk4error.h> 25#else 26#include <dktools-4/dk4error.h> 27#endif 28#endif 29 30#ifdef __cplusplus 31extern "C" { 32#endif 33 34/** Find current working directory. 35 @param dptr Destination buffer pointer. 36 @param sz Buffer size. 37 @param erp Error report, may be NULL. 38 @return 1 on success, 0 on error. 39*/ 40int 41dk4getcwd(dkChar *dptr, size_t sz, dk4_er_t *erp); 42 43/** Find current working directory, return string in newly 44 allocated memory. 45 @param erp Error report, may be NULL. 46 @return Valid pointer to newly allocated memory containing 47 the directory name on success, NULL on error. 48 On success, use dk4mem_free() to release the memory when done 49 with it. 50 51 Error codes: 52 - DK4_E_SYSTEM<br> 53 with errno in iDetails if getcwd() or _getcwd() failed 54 or GetLastError() result in iDetails if GetCurrentDirectoryA() 55 failed. 56 - DK4_E_INVALID_ARGUMENTS<br> 57 if src is a NULL pointer, 58 - DK4_E_MATH_OVERFLOW<br> 59 on mathematical overflow in size calculation, 60 - DK4_E_MEMORY<br> 61 if no memory is available. 62*/ 63dkChar * 64dk4getcwd_dup(dk4_er_t *erp); 65 66#ifdef __cplusplus 67} 68#endif 69 70 71%% module 72 73#include "dk4conf.h" 74#include <libdk4c/dk4getcwdd.h> 75 76#if DK4_CHAR_SIZE > 1 77#include <libdk4c/dk4getcwdw.h> 78#else 79#include <libdk4c/dk4getcwd8.h> 80#endif 81 82#if DK4_HAVE_ASSERT_H 83#ifndef ASSERT_H_INCLUDED 84#include <assert.h> 85#define ASSERT_H_INCLUDED 1 86#endif 87#endif 88 89 90$!trace-include 91 92 93 94int 95dk4getcwd(dkChar *dptr, size_t sz, dk4_er_t *erp) 96{ 97#if DK4_USE_ASSERT 98 assert(NULL != dptr); 99 assert(0 < sz); 100#endif 101#if DK4_CHAR_SIZE > 1 102 return ( 103 dk4getcwd_wc(dptr, sz, erp) 104 ); 105#else 106 return ( 107 dk4getcwd_c8(dptr, sz, erp) 108 ); 109#endif 110} 111 112 113 114dkChar * 115dk4getcwd_dup(dk4_er_t *erp) 116{ 117#if DK4_CHAR_SIZE > 1 118 return ( 119 dk4getcwd_wc_dup(erp) 120 ); 121#else 122 return ( 123 dk4getcwd_c8_dup(erp) 124 ); 125#endif 126} 127 128