PDA

View Full Version : C Help Thread: The Next Generation


Sir Penguin
19-09-2004, 04:48:51
OK, first question:

As far as I can find, directory operations come from the dirent.h header file. I mean, functions like opendir() and readdir(), as well as the DIR type for directory streams. In cygwin, gcc knows about dirent.h; but Visual Studio .NET 2K3 Pro doesn't. What's Visual Studio's equivalent?

SP

Venom
23-09-2004, 17:34:53
You have the MSDN collection for .Net 2k3? If so, I imagine all the include files are listed in there. Either that or kbase on microsoft.com/

Sir Penguin
23-09-2004, 19:52:53
I don't have the MSDN collection. I've given up on VS anyway, except when my Internet connection's down and I need a popup that lists a function's arguments.

SP

Sir Penguin
26-09-2004, 22:57:34
strncpy(dir_tok,&strtok(path,":"),80);

Without the & in front of strtok, gcc warns,
eexec.c:23: warning: passing arg 2 of `strncpy' makes pointer from integer witho
ut a cast
My partner said to put the & in front, and now gcc says,
eexec.c:23: error: invalid lvalue in unary `&'
So, I guess I'm not supposed to tell C to pass on the address of a function call. So how am I supposed to get the results of strtok into a char*?

SP

Sir Penguin
27-09-2004, 05:24:56
GDB says that the value from strtok gets into dir_tok just fine. Huh.

SP

Scabrous Birdseed
27-09-2004, 10:10:30
You partner? So YOU'RE asher's boyfriend.

zmama
27-09-2004, 10:17:12
How offensive! SP is as gay as they come but he has better taste than that! ;)

Sir Penguin
27-09-2004, 20:43:34
Anyway, it's not good to have two computer people in the house. It's too easy to argue about who gets to take care of the network, who has to write the software, etc.

So I've given up on strncpy and strtok. I'm using

char* token;
token = strtok(path,":");

instead, which gives the same warning as before, but works fine and is more flexible.

SP

Sir Penguin
29-09-2004, 07:30:57
It's time for Guess The Bug! Guess which part of this code caused us two hours of frustration this afternoon, assuming correct input. Hint: it causes an infinite amount of process spawning. Another hint: this function is called in the shell's main loop.

void exec_external_cmd(char* cmd_name,char** args,int signum)
{
int *status;
//printf("%s",args);
int pid;
pid = fork();
if(pid == 0){
//Parent
if(signum == WNOHANG){
//enter info
}
waitpid(pid,&status,signum);
}else{
//Child
execv(cmd_name,args);
}
}

SP

LoD
29-09-2004, 07:57:22
Let me guess:

pid = fork();

?

Sir Penguin
29-09-2004, 18:45:38
Nope, but close.

SP

LoD
29-09-2004, 20:10:15
So, by my guess it's additionaly:

waitpid(pid,&status,signum);

You ask the parent process to wait for the termination of it's (forked) child, but that process in return waits for its child, and so on, right?

Sir Penguin
29-09-2004, 20:32:37
You're dancing around the answer, but still not quite right.

Interestingly, this morning the IT guys got pissed off with my teacher because the C SC server (Mayne) crashed and burned. Apparently some other people in my class had the same problem we did, but they were all logged into Mayne through ssh instead of logged into the lab computers (like we were). My teacher calculated the worst-case number of processes under normal circumstances, and it worked out to about 1500 (number of students * maximum number of processes per test). Mayne was running 16000 processes before it gave up this morning. :lol:

SP

LoD
01-10-2004, 23:50:47
Alright, I give up.

And :lol: @ the 16000 processes...

Sir Penguin
03-10-2004, 19:15:09
The fork() call returns 0 if the process is the child, and it returns the child's PID if the process is the parent. The first if should be

if (pid != 0) {}

:mad:

SP

Sir Penguin
03-10-2004, 19:18:28
I didn't write that code, but this one's mine:

if (dir_tok[strlen(dir_tok)-1] != '/') {
dir_tok[strlen(dir_tok)] = '/';
dir_tok[strlen(dir_tok)+1] = '\00';
}

SP