Skip to content

Add unlink(2) implementation for CP/M. #235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: default
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions plat/cpm/libsys/unlink.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include <errno.h>
#include <unistd.h>
#include <cpm.h>
#include "cpmsys.h"

int unlink(const char* path)
{
uint8_t fd = 0;
struct FCBE* fcbe = &__fd[0];
uint8_t olduser;

__init_file_descriptors();
while (fd != NUM_FILE_DESCRIPTORS)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's been a while since I looked at this code, but I believe that this chunk is trying to find a free FCBE structure for use when parsing the filename, right? I think it would actually be more efficient to have a static structure used by unlink() instead --- the size of the structure is probably smaller than the size of the code needed to manage allocating one.

{
if (fcbe->fcb.f[0] == 0)
break;
fd++;
fcbe++;
}
if (fd == NUM_FILE_DESCRIPTORS)
{
errno = EMFILE;
return -1;
}

fcbe->user = cpm_parse_filename(&fcbe->fcb, path);

olduser = cpm_get_user();
cpm_set_user(fcbe->user);

if (cpm_delete_file(&fcbe->fcb) == 0xff)
{
fcbe->fcb.f[0] = 0;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUIC, this will leak the FCBE if the call succeeds. (I assume you don't want to allocate one permanently, right?)

errno = EIO;
return -1;
}

return 0;
}