1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-27 12:29:33 +00:00

Allow a third, optional filename argument for cbm_opendir.

git-svn-id: svn://svn.cc65.org/cc65/trunk@5683 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
uz 2012-06-04 18:32:38 +00:00
parent e5cdab4544
commit 2f87dbc27e
2 changed files with 27 additions and 13 deletions

View File

@ -116,7 +116,7 @@ extern char _filetype; /* Defaults to 'u' */
#define CH_LIRA 92 #define CH_LIRA 92
#define CH_ESC 27 #define CH_ESC 27
/*****************************************************************************/ /*****************************************************************************/
/* Definitions for directory reading functions */ /* Definitions for directory reading functions */
@ -150,9 +150,9 @@ struct cbm_dirent {
}; };
unsigned char __fastcall__ _cbm_filetype (unsigned char c); unsigned char __fastcall__ _cbm_filetype (unsigned char c);
/* Map the start character for a file type to one of the file types above. /* Map the start character for a file type to one of the file types above.
* Note: 'd' will always mapped to CBM_T_DEL. The calling function has to * Note: 'd' will always mapped to CBM_T_DEL. The calling function has to
* look at the following character to determine if the file type is actually * look at the following character to determine if the file type is actually
* CBM_T_DIR. * CBM_T_DIR.
* This is a function used by the implementation. There is usually no need * This is a function used by the implementation. There is usually no need
* to call it from user code. * to call it from user code.
@ -274,10 +274,11 @@ int __fastcall__ cbm_write (unsigned char lfn, const void* buffer,
* _oserror contains an error-code, then (see above table). * _oserror contains an error-code, then (see above table).
*/ */
unsigned char __fastcall__ cbm_opendir (unsigned char lfn, unsigned char device); unsigned char cbm_opendir (unsigned char lfn, unsigned char device, ...);
/* Opens directory listing. /* Opens directory listing. Returns 0 if opening directory was successful;
* Returns 0 if openning directory was successful; * otherwise, an error-code corresponding to cbm_open(). As an optional
* otherwise, an error-code corresponding to cbm_open(). * argument, the name of the directory may be passed to the function. If
* no explicit name is specified, "$" is used.
*/ */
unsigned char __fastcall__ cbm_readdir (unsigned char lfn, unsigned char __fastcall__ cbm_readdir (unsigned char lfn,

View File

@ -13,18 +13,31 @@
/* in directory listings). */ /* in directory listings). */
#include <stdarg.h>
#include <cbm.h> #include <cbm.h>
#include <errno.h> #include <errno.h>
/* Opens directory listing. /* Opens directory listing. Returns 0 if opening directory was successful;
** Returns 0 if openning directory was successful; ** otherwise, an error-code corresponding to cbm_open(). As an optional
** otherwise, an error-code corresponding to cbm_open(). ** argument, the name of the directory may be passed to the function. If
** no explicit name is specified, "$" is used.
*/ */
unsigned char __fastcall__ cbm_opendir (unsigned char lfn, unsigned char device) unsigned char cbm_opendir (unsigned char lfn, unsigned char device, ...)
{ {
if (cbm_open (lfn, device, CBM_READ, "$") == 0) { va_list ap;
const char* name = "$";
/* The name used in cbm_open may optionally be passed */
if (__argsize__ == 4) {
va_start (ap, device);
name = va_arg (ap, const char*);
va_end (ap);
}
/* Open the directory */
if (cbm_open (lfn, device, CBM_READ, name) == 0) {
if ((_oserror = cbm_k_chkin (lfn)) == 0) { if ((_oserror = cbm_k_chkin (lfn)) == 0) {
/* Ignore start address */ /* Ignore start address */
cbm_k_basin(); cbm_k_basin();