Compiler error when building Netpbm program

66 Views Asked by At

I'm trying to build a specific program from the Netpbm library, specifically pamenlarge. When running make pamenlarge, I get the following error:

pmfileio.c:216:22: error: implicitly declaring library function 'strdup' with type 'char *(const char *)' [-Werror,-Wimplicit-function-declaration]
    filenameBuffer = strdup(filenameTemplate);
                     ^
pmfileio.c:216:22: note: include the header <string.h> or explicitly provide a declaration for 'strdup'

I checked pmfileio.c and <string.h> is included. Alternatively, I tried explicitely defining the function strdup() from open source material, but the same error message popped up.

Here are the includes in pmfileio.c:


#define _SVID_SOURCE
    /* Make sure P_tmpdir is defined in GNU libc 2.0.7 (_XOPEN_SOURCE 500
       does it in other libc's).  pm_config.h defines TMPDIR as P_tmpdir
       in some environments.
    */
#define _BSD_SOURCE    /* Make sure strdup is defined */
#define _XOPEN_SOURCE 500    /* Make sure ftello, fseeko, strdup are defined */
#define _LARGEFILE_SOURCE 1  /* Make sure ftello, fseeko are defined */
#define _LARGEFILE64_SOURCE 1 
#define _FILE_OFFSET_BITS 64
    /* This means ftello() is really ftello64() and returns a 64 bit file
       position.  Unless the C library doesn't have ftello64(), in which 
       case ftello() is still just ftello().

       Likewise for all the other C library file functions.

       And off_t and fpos_t are 64 bit types instead of 32.  Consequently,
       pm_filepos_t might be 64 bits instead of 32.
    */
#define _LARGE_FILES  
    /* This does for AIX what _FILE_OFFSET_BITS=64 does for GNU */
#define _LARGE_FILE_API
    /* This makes the the x64() functions available on AIX */

#include "netpbm/pm_config.h"
#include <unistd.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <stdarg.h>
#include <string.h>
#include <errno.h>
#if HAVE_IO_H
  #include <io.h>  /* For mktemp */
#endif

#include "netpbm/pm_c_util.h"
#include "netpbm/mallocvar.h"
#include "netpbm/nstring.h"

#include "pm.h"

Here's the actual function where strdup is called:

static void
makeTmpfileWithTemplate(const char *  const filenameTemplate,
                        int *         const fdP,
                        const char ** const filenameP,
                        const char ** const errorP) {
    
    char * filenameBuffer;  /* malloc'ed */

    filenameBuffer = strdup(filenameTemplate); // The error is on this line here

    if (filenameBuffer == NULL)
        pm_asprintf(errorP, "Unable to allocate storage for temporary "
                    "file name");
    else {
        int rc;
        
        rc = mkstemp2(filenameBuffer);
        
        if (rc < 0)
            pm_asprintf(errorP,
                        "Unable to create temporary file according to name "
                        "pattern '%s'.  mkstemp() failed with errno %d (%s)",
                        filenameTemplate, errno, strerror(errno));
        else {
            *fdP = rc;
            *filenameP = filenameBuffer;
            *errorP = NULL;
        }
        if (*errorP)
            pm_strfree(filenameBuffer);
    }
}

Thank you in advance, I've been stuck trying to build this and don't really know where to go from here.

Update: I believe this project is running on C99, where a number of these functions are not available. How do I update this so I have access to these functions?

0

There are 0 best solutions below