summaryrefslogtreecommitdiff
path: root/support/dktools/dk4dir08.ctr
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2020-09-20 03:03:26 +0000
committerNorbert Preining <norbert@preining.info>2020-09-20 03:03:26 +0000
commit1f457376b478257b88d4a857f5ec1b6155442dd7 (patch)
tree2a06a60551dea362cf8cb0cb0ba66c78608717c4 /support/dktools/dk4dir08.ctr
parentac690ca29ad5bf8a5203a65fd6252f7b564f4727 (diff)
CTAN sync 202009200303
Diffstat (limited to 'support/dktools/dk4dir08.ctr')
-rw-r--r--support/dktools/dk4dir08.ctr172
1 files changed, 166 insertions, 6 deletions
diff --git a/support/dktools/dk4dir08.ctr b/support/dktools/dk4dir08.ctr
index 4759371680..d65209f148 100644
--- a/support/dktools/dk4dir08.ctr
+++ b/support/dktools/dk4dir08.ctr
@@ -2,7 +2,7 @@
copyright owner = Dirk Krause
copyright year = 2015-xxxx
-license = bsd
+SPDX-License-Identifier: BSD-3-Clause
@@ -15,19 +15,35 @@ license = bsd
*/
#ifndef DK4CONF_H_INCLUDED
+#if DK4_BUILDING_DKTOOLS4
#include "dk4conf.h"
+#else
+#include <dktools-4/dk4conf.h>
+#endif
#endif
#ifndef DK4TYPES_H_INCLUDED
+#if DK4_BUILDING_DKTOOLS4
#include "dk4types.h"
+#else
+#include <dktools-4/dk4types.h>
+#endif
#endif
#ifndef DK4ERROR_H_INCLUDED
+#if DK4_BUILDING_DKTOOLS4
#include "dk4error.h"
+#else
+#include <dktools-4/dk4error.h>
+#endif
#endif
#ifndef DK4STO_H_INCLUDED
+#if DK4_BUILDING_DKTOOLS4
#include "dk4sto.h"
+#else
+#include <dktools-4/dk4sto.h>
+#endif
#endif
@@ -98,7 +114,7 @@ dk4dir_c8_reset(dk4_dir_c8_t *dptr);
file name expansion.
*/
const char *
-dk4dir_c8_get_path(dk4_dir_c8_t *dptr);
+dk4dir_c8_get_path(dk4_dir_c8_t const *dptr);
/** Retrieve next directory name.
@param dptr Directory structure.
@@ -136,7 +152,56 @@ dk4dir_c8_compare(const void *l, const void *r, int cr);
@return Maximum name length.
*/
size_t
-dk4dir_c8_get_max_entry_length(dk4_dir_c8_t *dptr);
+dk4dir_c8_get_max_entry_length(dk4_dir_c8_t const *dptr);
+
+/** Create full path name for short file name in existing buffer.
+ @param buffer Result buffer.
+ @param szbuf Size of result buffer.
+ @param pdir Directory fn was obtained from.
+ @param fn Short file or directory name.
+ @param erp Error report, may be NULL.
+ @return 1 on success, 0 on error.
+
+ Error codes:
+ - DK4_E_INVALID_ARGUMENTS<br>
+ if buffer, dirn or filen is NULL or szbuf is 0,
+ - DK4_E_BUFFER_TOO_SMALL<br>
+ if the buffer is too small.
+*/
+int
+dk4dir_c8_full_name_buffer(
+ char *buffer,
+ size_t szbuf,
+ dk4_dir_c8_t const *pdir,
+ char const *fn,
+ dk4_er_t *erp
+);
+
+/** Create full path name for short file name in newly allocated buffer.
+ @param pdir Directory fn was obtained from.
+ @param fn Short file or directory name.
+ @param erp Error report, may be NULL.
+ @return Valid pointer to newly allocated buffer on success,
+ NULL on error.
+ On success use dk4mem_free() to release the memory when done with
+ the name.
+
+ Error codes:
+ - DK4_E_INVALID_ARGUMENTS<br>
+ if pdir or fn is NULL,
+ - DK4_E_MATH_OVERFLOW<br>
+ if the size calculation results in a numeric overflow.
+ - DK4_E_MEMORY_ALLOCATION_FAILED<br>
+ if the memory allocation failed,
+ - DK4_E_BUFFER_TOO_SMALL<br>
+ if the buffer is too small.
+*/
+char *
+dk4dir_c8_full_name_new(
+ dk4_dir_c8_t const *pdir,
+ char const *fn,
+ dk4_er_t *erp
+);
#ifdef __cplusplus
}
@@ -159,6 +224,10 @@ dk4dir_c8_get_max_entry_length(dk4_dir_c8_t *dptr);
#include "dk4dir.h"
#endif
+#ifndef DK4PATH8_H_INCLUDED
+#include "dk4path8.h"
+#endif
+
#ifndef DK4STR8_H_INCLUDED
#include "dk4str8.h"
#endif
@@ -200,6 +269,15 @@ dk4dir_c8_get_max_entry_length(dk4_dir_c8_t *dptr);
#endif
#endif
+#if DK4_HAVE_ASSERT_H
+#ifndef ASSERT_H_INCLUDED
+#include <assert.h>
+#define ASSERT_H_INCLUDED 1
+#endif
+#endif
+
+#include "dk4unused.h"
+
$!trace-include
@@ -207,9 +285,11 @@ $!trace-include
int
-dk4dir_c8_compare(const void *l, const void *r, int cr)
+dk4dir_c8_compare(const void *l, const void *r, int DK4_ARG_UNUSED(cr) )
{
int back = 0;
+
+ DK4_UNUSED_ARG(cr)
if (NULL != l) {
if (NULL != r) {
back = dk4str8_pathcmp((const char *)l, (const char *)r);
@@ -247,6 +327,9 @@ void
dk4dir_c8_close(dk4_dir_c8_t *dptr)
{
$? "+ dk4dir_c8_close"
+#if DK4_USE_ASSERT
+ assert(NULL != dptr);
+#endif
if (NULL != dptr) {
dk4mem_release(dptr->path);
dk4dir_c8_clean_storage(dptr->s_dir, dptr->i_dir);
@@ -304,6 +387,9 @@ dk4dir_c8_fill_directory(dk4_dir_c8_t *dptr, int om, dk4_er_t *erp)
int isdir; /* Flag: Entry is directory */
int back = 0;
$? "+ dk4dir_c8_fill_directory"
+#if DK4_USE_ASSERT
+ assert(NULL != dptr);
+#endif
if (dk4str8_cpy_s(pab, sizeof(pab), dptr->path, erp)) {
if (dk4str8_cat_s(pab, sizeof(pab), dk4dir_c8_kw[3], erp)) {
if (dk4str8_cat_s(pab, sizeof(pab), dk4dir_c8_kw[4], erp)) {
@@ -367,6 +453,9 @@ dk4dir_c8_fill_directory(dk4_dir_c8_t *dptr, int om, dk4_er_t *erp)
int isdir = 0; /* Flag: Current item is directory */
int back = 0;
$? "+ dk4dir_c8_fill_directory"
+#if DK4_USE_ASSERT
+ assert(NULL != dptr);
+#endif
errno = 0;
dir = opendir(dptr->path);
if (NULL != dir) { $? ". opendir"
@@ -448,6 +537,9 @@ dk4dir_c8_open(const char *path, int om, dk4_er_t *erp)
dk4_dir_c8_t *back = NULL;
int ok = 0;
$? "+ dk4dir_c8_open \"%!8s\"", TR_8STR(path)
+#if DK4_USE_ASSERT
+ assert(NULL != path);
+#endif
if (NULL != path) {
#if DK4_ON_WINDOWS || DK4_HAVE_DIRENT_H
back = dk4mem_new(dk4_dir_c8_t, 1, erp);
@@ -501,6 +593,9 @@ void
dk4dir_c8_reset(dk4_dir_c8_t *dptr)
{
$? "+ dk4dir_c8_reset"
+#if DK4_USE_ASSERT
+ assert(NULL != dptr);
+#endif
if (NULL != dptr) {
if ((NULL != dptr->s_dir) && (NULL != dptr->i_dir)) {
dk4sto_it_reset(dptr->i_dir);
@@ -515,10 +610,13 @@ dk4dir_c8_reset(dk4_dir_c8_t *dptr)
const char *
-dk4dir_c8_get_path(dk4_dir_c8_t *dptr)
+dk4dir_c8_get_path(dk4_dir_c8_t const *dptr)
{
const char *back = NULL;
$? "+ dk4dir_c8_get_path"
+#if DK4_USE_ASSERT
+ assert(NULL != dptr);
+#endif
if (NULL != dptr) {
back = (const char *)(dptr->path);
}
@@ -533,6 +631,9 @@ dk4dir_c8_next_dir(dk4_dir_c8_t *dptr)
{
const char *back = NULL;
$? "+ dk4dir_c8_next_dir"
+#if DK4_USE_ASSERT
+ assert(NULL != dptr);
+#endif
if (NULL != dptr) {
if ((NULL != dptr->s_dir) && (NULL != dptr->i_dir)) {
back = (const char *)dk4sto_it_next(dptr->i_dir);
@@ -549,6 +650,9 @@ dk4dir_c8_next_file(dk4_dir_c8_t *dptr)
{
const char *back = NULL;
$? "+ dk4dir_c8_next_file"
+#if DK4_USE_ASSERT
+ assert(NULL != dptr);
+#endif
if (NULL != dptr) {
if ((NULL != dptr->s_file) && (NULL != dptr->i_file)) {
back = (const char *)dk4sto_it_next(dptr->i_file);
@@ -564,6 +668,9 @@ void
dk4dir_c8_skip_files(dk4_dir_c8_t *dptr)
{
$? "+ dk4dir_c8_skip_files"
+#if DK4_USE_ASSERT
+ assert(NULL != dptr);
+#endif
if (NULL != dptr) {
dk4dir_c8_clean_storage(dptr->s_file, dptr->i_file);
dptr->s_file = NULL; dptr->i_file = NULL;
@@ -574,10 +681,13 @@ dk4dir_c8_skip_files(dk4_dir_c8_t *dptr)
size_t
-dk4dir_c8_get_max_entry_length(dk4_dir_c8_t *dptr)
+dk4dir_c8_get_max_entry_length(dk4_dir_c8_t const *dptr)
{
size_t back = 0;
$? "+ dk4dir_c8_get_max_entry_length"
+#if DK4_USE_ASSERT
+ assert(NULL != dptr);
+#endif
if (NULL != dptr) {
back = dptr->maxlen;
}
@@ -586,3 +696,53 @@ dk4dir_c8_get_max_entry_length(dk4_dir_c8_t *dptr)
}
+
+int
+dk4dir_c8_full_name_buffer(
+ char *buffer,
+ size_t szbuf,
+ dk4_dir_c8_t const *pdir,
+ char const *fn,
+ dk4_er_t *erp
+)
+{
+ int back = 0;
+#if DK4_USE_ASSERT
+ assert(NULL != pdir);
+ assert(NULL != fn);
+ assert(NULL != buffer);
+ assert(0 < szbuf);
+#endif
+ if ((NULL != buffer) && (NULL != pdir) && (NULL != fn) && (0 < szbuf)) {
+ back = dk4path8_concatenate_buffer(buffer, szbuf, pdir->path, fn, erp);
+ }
+ else {
+ dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
+ }
+ return back;
+}
+
+
+
+char *
+dk4dir_c8_full_name_new(
+ dk4_dir_c8_t const *pdir,
+ char const *fn,
+ dk4_er_t *erp
+)
+{
+ char *back = NULL;
+#if DK4_USE_ASSERT
+ assert(NULL != pdir);
+ assert(NULL != fn);
+#endif
+ if ((NULL != pdir) && (NULL != fn)) {
+ back = dk4path8_concatenate_new(pdir->path, fn, erp);
+ }
+ else {
+ dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
+ }
+ return back;
+}
+
+