1
0
mirror of https://github.com/cc65/cc65.git synced 2024-12-23 19:29:37 +00:00
cc65/test/ref/strptr.c

131 lines
2.9 KiB
C
Raw Normal View History

2014-09-24 14:45:10 +00:00
/*
2022-04-17 14:07:52 +00:00
!!DESCRIPTION!!
2014-09-24 14:45:10 +00:00
!!ORIGIN!! testsuite
!!LICENCE!! Public Domain
!!AUTHOR!! Groepaz/Hitmen
*/
/*
this test reproduces a bug that prevented the testsuites directory
reading stuff for the c64 from working before. the bug appears to
only occur when optimizations are enabled. it also disappears if
the buffers inside the readdir function are declared static or
made global.
*/
/*#define STANDALONE*/
#ifdef STANDALONE
FILE *outfile=NULL;
#define OPENTEST() outfile=stdout;
#define CLOSETEST()
#else
#endif
2022-04-17 14:07:52 +00:00
2014-09-24 14:45:10 +00:00
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#define XNAME_MAX 16
struct Xdirent
{
2019-02-12 21:50:49 +00:00
char d_name[XNAME_MAX+1];
unsigned short d_off;
unsigned short d_reclen;
unsigned char d_type;
unsigned char d_namlen;
2014-09-24 14:45:10 +00:00
};
typedef struct
{
2019-02-12 21:50:49 +00:00
unsigned char fd;
unsigned short off;
char name[XNAME_MAX+1];
2014-09-24 14:45:10 +00:00
} XDIR;
unsigned char b1[4];
unsigned char b2[0x10]={" \"test\" "};
struct Xdirent *Xreaddir(XDIR *dir)
{
unsigned char buffer[0x40];
unsigned char temp;
unsigned char i,ii;
static struct Xdirent entry;
unsigned char fd;
static unsigned char ch;
2019-02-12 21:50:49 +00:00
entry.d_off=dir->off;
/* basic line-link / file-length */
memcpy(buffer,b1,4);
2022-04-17 14:07:52 +00:00
dir->off=dir->off+4;
2019-02-12 21:50:49 +00:00
entry.d_reclen=254*(buffer[2]+(buffer[3]<<8));
/* read file entry */
memcpy(buffer,b2,0x10);
2022-04-17 14:07:52 +00:00
dir->off=dir->off+i;
2019-02-12 21:50:49 +00:00
printf("Xreaddir: '%s'\n",buffer);
2022-04-17 14:07:52 +00:00
2019-02-12 21:50:49 +00:00
/* skip until either quote (file) or b (blocks free => end) */
i=0;ii=0;
while(i==0){
temp=buffer[ii];ii++;
if(ii>16){
/* something went wrong...this shouldnt happen! */
return(NULL);
}
else if(temp=='\"') i++;
else if(temp=='b') {
/* "blocks free" */
return(NULL);
}
}
printf("Xreaddir: '%s'\n",buffer);
/* process file entry */
i=0; temp=buffer[ii];ii++;
while(temp!='\"'){
entry.d_name[i]=temp;
i++;
temp=buffer[ii];ii++;
}
entry.d_name[i]=0;
entry.d_namlen=i;
/* set type flag */
return(&entry);
2014-09-24 14:45:10 +00:00
}
int main(void)
{
char mydirname[XNAME_MAX+1]=".";
XDIR mydir;
struct Xdirent *mydirent;
2022-04-17 14:07:52 +00:00
2014-09-24 14:45:10 +00:00
printf("start\n");
2022-04-17 14:07:52 +00:00
2014-09-24 14:45:10 +00:00
if((mydirent=Xreaddir(&mydir))==NULL)
{
2019-02-12 21:50:49 +00:00
printf("NULL\n");
2014-09-24 14:45:10 +00:00
}
else
{
2019-02-12 21:50:49 +00:00
printf("=%s\n",mydirent->d_name);
2014-09-24 14:45:10 +00:00
}
printf("done\n");
return 0;
}