file existnse
Hi Guys, I seem to stumble upon something really weird.
Code:
char a[512] = ""; Also, i am wondering how it executed the printf(....) statement. If the filename was infact "/", it shouldn't have even tried the "unlink" operation according to the code logic right? It should have exit'd the "if" condition right after "access()". Kindly help.... |
Quote:
Here's a complete program that mimics what you have posted, and it functions correctly. Code:
#include <unistd.h> |
An empty file-name could possibly be interpreted as "/" but in any case it's a nonsensical situation as-writ.
|
Thank you DWhitney.. Yes the intent is to delete a file. I think doing a "stat" would be better as you mentioned... Yes in the first few lines of the function there is a do while loop within which if this file "a" is NULL then we break out of the loop and hit the deletion code which I've pasted above.
This confirms the issue right? thanks again dWhitney. ur thoughts are just priceless..cheerio :) |
Quote:
|
Quote:
Code:
#include <errno.h> |
Quote:
|
Hi Dwhitney67, i really appreciate your timely response. I have one more connected problem that I need some pointers. Pls assist:
In my header file I have a macro defined as; Code:
#define QWE 1 Code:
void abc() { |
fprintf() can be used to write to stdout, stderr, or any other stream (such as a file).
So I'm not sure why you require different implementations for the ABC() function, unless you are doing something drastically different when writing to a file (for example, in lieu of writing the data in ASCII format, you are writing it in binary). So, if you are not doing anything different, then implement something like the following: Code:
void ABC(FILE* stream, params...) |
Quote:
|
Quote:
|
Quote:
If you are referring to '/', then that is a directory. It is the root (not to be confused with the user 'root') directory of a Linux/Unix system. |
Hello I would to get confirmation on this piece of code that I've written. I am basically trying do an "scp" and trying to log useful information onto the console if it fails:
Code:
error = WEXITSTATUS(status); Now i want to make the error more readable not throw a print saying "scp exited with status 1"... is this better?-> Code:
printf( "WHOOPS: scp exited with status %s\n", strerror(error)); |
akshay_satish -
You should have created a new thread for your latest query; it is unrelated to the one that you used to open this thread. But to answer your question, the command 'scp' returns 0 on success, and some number greater than 0 (this could be any number!) on a failure. If a failure occurs, I don't believe the error number corresponds to anything other than to denote that an error occurred. Thus the use of strerror() would not be wise in this situation. On my system, a failed 'scp' request, using the system() command, returns a status of 256; this translates to "Unknown error" when passed to strerror(). My recommendation is to avoid using system(), and instead use popen() so that you may read the output produced by the system command. |
I am extremely sorry DWhitney67.. Should I create one more now or can you forgive me for this question? I'll make sure to create unique threads for separate questions. Thank you very again for your valuable thoughts...Adding on...
Actually this is how I am doing the scp; Code:
//argv will contain the scp cmd |
Quote:
Did you define your own argv array to contain a reference to the scp command and associated arguments? |
yes, i used my own argv array which is why I thought I could use strerror() and thought posix_spawnp will give me the correct status:
SCP Return Codes 0 Operation was successful 1 General error in file copy 2 Destination is not directory, but it should be 3 Maximum symlink level exceeded 4 Connecting to host failed. 5 Connection broken 6 File does not exist 7 No permission to access file. 8 General error in sftp protocol 9 File transfer protocol mismatch 10 No file matches a given criteria 65 Host not allowed to connect 66 General error in ssh protocol 67 Key exchange failed 68 Reserved 69 MAC error 70 Compression error 71 Service not available 72 Protocol version not supported 73 Host key not verifiable 74 Connection failed 75 Disconnected by application 76 Too many connections 77 Authentication cancelled by user 78 No more authentication methods available 79 Invalid user name Code:
argv[0] = "scp"; |
Again, according to the man-page of scp, 0 is returned on success, and a number > 0 is returned on the occurrence of an error.
I do not know where you obtained the list of status values; it does not appear on the man-page for 'scp', and I have taken the effort to check on Linux, HP-UX, and a Mac. Are you on a different OS? |
Quote:
|
Quote:
Code:
#include <stdio.h> |
Quote:
|
Quote:
I am giving a wrong scp command on purpose (this is how it would be stored internally in "cmd" per your code): Code:
scp -p -o StrictHostKeychecking=no aks@something.com:/test/tmp /tmp coudl you pls explain the below 2 lines pls: Code:
fgets(output, sizeof(output), cmd_fp); |
Quote:
Code:
/usr/bin/scp -p -o StrictHostKeychecking=no aks@something.com:/test/tmp /tmp Code:
Error: ssh: Could not resolve hostname something.com: Name or service not known Quote:
P.S. Here's the modified code I tested with: Code:
#include <stdio.h> EDIT: I'm wagering that you forgot to place this at the end of your command buffer in your code: "2>&1". This directs standard-error to standard-out, thus enabling the fgets() to do its job. |
Hi dwhitney, i see you have replied but I am able to view only one page on this thread.. has this been lost or something?
|
Quote:
|
Quote:
|
All times are GMT -5. The time now is 04:38 PM. |