Fopen_s not allowed in Ubuntu

I want to open a file, so I am using fopen_s function under ubuntu. Although I #include <stdio.h>

have as stated here http://en.cppreference.com/w/c/io/fopen , I get that the error function was not declared in scope. Please help me what I am doing wrong and how to do it?

FILE *fp;
fopen_s(&fp, strFilename.c_str(), "rb");
if (fp == NULL){
    cout << "cannot open " << strFilename.c_str();
    return false;
}

fclose(fp);

      

+3


source to share


2 answers


Searching for glibc on Linux finds no evidence that fopen_s

() is implemented in glibc on Linux.



I don't mention fopen_s

() in the POSIX spec . It seems to me that fopen_s

() is a non-portable library function implemented only in Microsoft Windows.

+1


source


Try using fopen ()

#ifdef __unix
#define fopen_s(pFile,filename,mode) ((*(pFile))=fopen((filename),  (mode)))==NULL
#endif

      



reference: Is there a way to use fopen_s () with GCC, or at least create a #define about it?

0


source







All Articles