开云体育

ctrl + shift + ? for shortcuts
© 2025 开云体育

Odd C compiler behavior on P390


 

For some reason argv[1] does not get converted properly. If the folder name is hard coded the program works fine. If its value is passed through argv[1] the program will display the value correctly, but no directory list gets retrieved. This issue happens on MVS, but if the code is compiled on Linux it works as expected. Here is the code.? The code below will only display the contents of / but not its branches.


?#define _POSIX_SOURCE
?#include <dirent.h>
?#include <errno.h>
?#include <sys/stat.h>
?#include <sys/types.h>
?#undef _POSIX_SOURCE
?#include<stdlib.h>
?#include<stdio.h>
?#include <unistd.h>
?#include <string.h>
?#include <sys/wait.h>
?#include <grp.h>
?#include <pwd.h>
?#include <time.h>
?#include <fcntl.h>
??? char path[1024];
void listdir(const char *name, int indent,char *other)
{
??? DIR *dir;
??? struct dirent *entry;
?????????????????????????????????????????????????????? ?
??? puts(name);
??? if (!(dir = opendir(name)))
??????? return;
?????????????????????????????????????????????????????? ?
??? while ((entry = readdir(dir)) != NULL) {
??????????? printf("%*s- %s\n", indent, "", entry->d_name);
??????? if (strcmp(entry->d_name, other) == 0)
??????? listdir(entry->d_name,? 2,other);
??? }
??? closedir(dir);
}
???????????????????????????????????????????????????????????????? ?
int main(int argc, char **argv)
??? {
???? char* foldername = ".";
???? puts(argv[1]);
???? listdir(foldername, 0,argv[1]);
???? return 0;
?}





Join [email protected] to automatically receive all group messages.