0
fileDes= open(dbPathname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
}
printf("File %s opened successfully with handle %d\n", dbPathname, fileDes );
if(-1 == fileDes)
{
    PERS_ERROR( "pers_db_open_default: File %s opened Failed %d \n", dbPathname, fileDes );
    return NULL; //return PERS_COM_FAILURE;
}

*db = fileDes;
printf("file info:  FD=[%d], &FD=[%d], fileDes=[%d]  \n", (*db),(db), fileDes );

if( 0 != fstat(fileDes, &sb))
{;
    perror("fileInfo() fstat-perror=   \n");
    printf("\nfstat error: [%s] and st.st_mode is [%d]\n",strerror(errno), sb.st_mode);

    return NULL; 
}

output:-

fileInfo() fstat-perror=
: Invalid argument
Segmentation fault (core dumped)
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
  • 1
    Can you please post the complete code ? As we don't know what's the type of `db` and `sb`. – Achal Feb 28 '19 at 06:05
  • What is that `}` doing on the line after the `fileDes` assignment? – Barmar Feb 28 '19 at 06:08
  • int *db = (int*)malloc(sizeof(int)); struct stat sb; – Gourav T Feb 28 '19 at 06:09
  • 3
    [don't cast malloc](https://stackoverflow.com/questions/605845/do-i-cast-the-result-of-malloc) – Barmar Feb 28 '19 at 06:10
  • Where is the rest of the output? What do the `File ... opened` and `file info` lines say? – Barmar Feb 28 '19 at 06:11
  • 2
    Please provide a [mcve] that shows everything you're doing. It's impossible to tell what's wrong from this snippet. – Barmar Feb 28 '19 at 06:14
  • Why there is a semicolon after } `if( 0 != fstat(fileDes, &sb)) {;` – Sameer Naik Feb 28 '19 at 06:17
  • 3
    @GouravT Here `int db = (int)malloc(sizeof(int));` `db` should be of pointer type, isn't it ? – Achal Feb 28 '19 at 06:29
  • 2
    @GouravT `int db = (int)malloc(sizeof(int));`: allocating memory for a single `int` is pointless, there are probably other things wrong elsewhere in your code. Please read this: [ask] and [edit] your question and show a [mcve]. All relevant information must be _in the question_. – Jabberwocky Feb 28 '19 at 06:47
  • File /mnt/data/Persistence/mnt-wt/App/wt.db opened successfully with handle 7 pers_db_open_default FD=[7], &FD=[922543632], fileDes=[7] fileInfo() fstat-perror= : Invalid argument – Gourav T Feb 28 '19 at 08:39
  • 1
    Assuming `db` is a pointer to `int`, `printf("file info: FD=[%d], &FD=[%d], fileDes=[%d] \n", (*db),(db), fileDes );` invokes undefined behavior by using the improper format specifier `%d` to print its value. – Andrew Henle Feb 28 '19 at 10:21
  • You are on 64bit? – alk Feb 28 '19 at 14:27

0 Answers0