Skip to content

Commit

Permalink
Merge pull request #8 from zopencommunity/has_member
Browse files Browse the repository at this point in the history
Expose has_member
  • Loading branch information
IgorTodorovskiIBM authored Nov 5, 2024
2 parents 07d5111 + 72e6ce8 commit fcabd76
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
5 changes: 5 additions & 0 deletions include/dio.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,11 @@
*/
int is_binary(const char *str, int length);

/*
* has_member: checks if the dataset has a member
*/
int has_member(struct DFILE *dfile);

/*
write_dataset_to_temp_file:
Helper function to write dataset contents to a temporary file.
Expand Down
12 changes: 6 additions & 6 deletions src/dio.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ void strlower(char* str)
}
}


static int has_member(struct DIFILE* difile)
int has_member(struct DFILE* dfile)
{
struct DIFILE* difile = (struct DIFILE*) dfile->internal;
return difile->member_name[0] != '\0';
}

Expand Down Expand Up @@ -435,7 +435,7 @@ static const char* dstates(enum DSTATE dstate)
static FILE* opendd(struct DFILE* dfile, struct DIFILE* difile, const char* openfmt)
{
char copendd[DD_MAX+MEM_MAX+2+2+2+1+1];
if (has_member(difile)) {
if (has_member(dfile)) {
sprintf(copendd, "//DD:%s(%s)", difile->ddname, difile->member_name);
} else {
sprintf(copendd, "//DD:%s", difile->ddname);
Expand Down Expand Up @@ -525,7 +525,7 @@ struct DFILE* open_dataset(const char* dataset_name, FILE* logstream)
if (difile->fp) {
difile->dstate = D_READWRITE_BINARY;
} else {
if ((errno == ERRNO_NONEXISTANT_FILE) && has_member(difile)) {
if ((errno == ERRNO_NONEXISTANT_FILE) && has_member(dfile)) {
/*
* This is a PDS or PDSE member, and the member does not exist yet.
* We need to open the member in write to get the attributes of the actual
Expand Down Expand Up @@ -830,7 +830,7 @@ const char* member_name(struct DFILE* dfile, char* member_copy)
{
struct DIFILE* difile = (struct DIFILE*) dfile->internal;

if (has_member(difile)) {
if (has_member(dfile)) {
size_t len = strlen(difile->member_name);
memcpy(member_copy, difile->member_name, len);
member_copy[len] = '\0';
Expand Down Expand Up @@ -876,7 +876,7 @@ const char* low_level_qualifier(struct DFILE* dfile, char* llq_copy)
const char* map_to_unixfile(struct DFILE* dfile, char* unixfile) {
struct DIFILE* difile = (struct DIFILE*) dfile->internal;

if (has_member(difile)) {
if (has_member(dfile)) {
if (has_mlqs(difile)) {
sprintf(unixfile, "%s.%s.%s.%s", difile->hlq, difile->mlqs, difile->member_name, difile->unix_extension);
} else {
Expand Down

0 comments on commit fcabd76

Please sign in to comment.