Skip to content

str*_s() functions needs __STDC_WANT_LIB_EXT1__ to be defined.

Martin Řehák requested to merge rehak/poppler:master into master

On Solaris, I got following errors during compile:

/builds/mrehak/workspace/poppler/components/desktop/poppler/poppler-20.10.0/test/perf-test.cc: In function 'FindFileSta
te* find_file_open(const char*, const char*)':             
/builds/mrehak/workspace/poppler/components/desktop/poppler/poppler-20.10.0/test/perf-test.cc:530:5: error: 'strcpy_s' 
was not declared in this scope
  530 |     strcpy_s(s->path, sizeof(s->path), path);
      |     ^~~~~~~~                                       
/builds/mrehak/workspace/poppler/components/desktop/poppler/poppler-20.10.0/test/perf-test.cc: In function 'char* makep
ath(char*, int, const char*, const char*)':                
/builds/mrehak/workspace/poppler/components/desktop/poppler/poppler-20.10.0/test/perf-test.cc:554:5: error: 'strcpy_s' 
was not declared in this scope                             
  554 |     strcpy_s(buf, buf_size, path);
      |     ^~~~~~~~                                       
/builds/mrehak/workspace/poppler/components/desktop/poppler/poppler-20.10.0/test/perf-test.cc:560:5: error: 'strcat_s' 
was not declared in this scope                             
  560 |     strcat_s(buf, buf_size, filename);
      |     ^~~~~~~~

These fail beucase HAVE_STRCPY_S and HAVE_STRCAT_S are defined and STDC_WANT_LIB_EXT1 is not. According to https://en.cppreference.com/w/c/string/byte/strcpy :

As with all bounds-checked functions, strcpy_s is only guaranteed to be available if __STDC_LIB_EXT1__ is defined by the implementation and if the user defines __STDC_WANT_LIB_EXT1__ to the integer constant 1 before including string.h.

My one liner resolves this issue.

Edited by Martin Řehák

Merge request reports