Very inexperienced C guy here, but I've been programming
the shell and tcl for a couple of years. I have a script
with this code in it:
cat << EOF > $PWD/statfile.c
#include <stdio.h>
#include <unistd.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <sys/types.h>
int main(void) {
struct stat *fbuf = NULL;
if ( stat("$filename",fbuf) != 0) {
fprintf(stderr,"%s, stat()\n","Error"
abort();
} else {
printf("%s ctime\n %s atime\n %s mtime\n", fbuf->st_ctime,
fbuf->st_atime, fbuf->st_mtime);
EXIT_SUCCESS;
}
}
EOF
Forgive the formatting,please.
I know there are things wrong with it, but being so
inexperienced with C is a problem. It segfaults.
I've run it through the debugger(gdb), but really
have yet to learn where it is wrong on my own.
I know there is an error in typing for the printf
call for one of the struct member pointers, but
am at a loss beyond this.
The remainder of the C relevant portions of the script looks like this so everyone can be sure that is not the cause:
if [ condition ] ; then
gcc statfile.c -o statout || a="Failed to compile."
test -z "$a" && chmod 700 statout && exec statout
echo "C version."
rm $PWD/statout ; rm $PWD/statfile.c ; rm $PWD/statout
fi
TIA
the shell and tcl for a couple of years. I have a script
with this code in it:
cat << EOF > $PWD/statfile.c
#include <stdio.h>
#include <unistd.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <sys/types.h>
int main(void) {
struct stat *fbuf = NULL;
if ( stat("$filename",fbuf) != 0) {
fprintf(stderr,"%s, stat()\n","Error"
abort();
} else {
printf("%s ctime\n %s atime\n %s mtime\n", fbuf->st_ctime,
fbuf->st_atime, fbuf->st_mtime);
EXIT_SUCCESS;
}
}
EOF
Forgive the formatting,please.
I know there are things wrong with it, but being so
inexperienced with C is a problem. It segfaults.
I've run it through the debugger(gdb), but really
have yet to learn where it is wrong on my own.
I know there is an error in typing for the printf
call for one of the struct member pointers, but
am at a loss beyond this.
The remainder of the C relevant portions of the script looks like this so everyone can be sure that is not the cause:
if [ condition ] ; then
gcc statfile.c -o statout || a="Failed to compile."
test -z "$a" && chmod 700 statout && exec statout
echo "C version."
rm $PWD/statout ; rm $PWD/statfile.c ; rm $PWD/statout
fi
TIA