Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6066577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:30:57+00:00 2026-05-23T09:30:57+00:00

I’m integrating a C library into an Objective-C app for iOS. I’m not very

  • 0

I’m integrating a C library into an Objective-C app for iOS. I’m not very C-savvy… I know just enough to be dangerous.

The C function declaration is this:

extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file,
                         unz_file_info *pfile_info,
                         char *szFileName,
                         uLong fileNameBufferSize,
                         void *extraField,
                         uLong extraFieldBufferSize,
                         char *szComment,
                         uLong commentBufferSize));

I am really only interested in the szFileName. I know I can ignore the void* and char* by passing NULL. Can I pass some sort of NULL-equivalent to the uLong params? I’m getting a compiler warning about converting to pointer without a cast.

Here’s my loop for calling this function, in case anyone wants to comment on that. Did I do the malloc/free correctly? I’m not used to the low-level C stuff. I know people complain about Objective-C reference counting but in comparison it’s pretty luxurious 🙂

unz_file_info pfile_info;
char *szFileName = malloc(1024);
uLong fileNameBufferSize;
uLong commentBufferSize;
uLong extraFieldBufferSize;

do {
    int ret = unzGetCurrentFileInfo(zipFile, &pfile_info, szFileName, fileNameBufferSize, NULL, extraFieldBufferSize, NULL, commentBufferSize);
    NSLog(@"get info ret %i filename size %lu, filename %s", ret, pfile_info.size_filename, szFileName);
    // do other stuff here with the filename
}
while (unzGoToNextFile(zipFile) == UNZ_OK);
free(szFileName);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T09:30:57+00:00Added an answer on May 23, 2026 at 9:30 am

    The ulong parameters are the sizes of the buffer arguments. This is so the function knows how big those buffers are so it doesn’t overflow them.

    If you need the fileName argument, you must supply a correct fileNameBufferSize.

    As for whether you actually can pass in a NULL pointer to the pointer arguments, only the documentation(or source code) for this function can tell you. Or if the documentation doesn’t tell you, you’ll have to do some basic science experiments on the function and see how it behaves.

    Assuming the function accepts NULL pointers for parameters you don’t want filled in, you’d likely pass 0 as the value for the ulong parameters.

    You’ll have to do:

    unz_file_info pfile_info;
    char *szFileName = malloc(1024);
    uLong fileNameBufferSize = 1024;
    if( szFileName == NULL) {
      //handle error
      return;
    }
    
    do {
        int ret = unzGetCurrentFileInfo(zipFile, &pfile_info, szFileName, fileNameBufferSize, NULL, 0, NULL, 0);
        NSLog(@"get info ret %i filename size %lu, filename %s", ret, pfile_info.size_filename, szFileName);
        // do other stuff here with the filename
    }
    while (unzGoToNextFile(zipFile) == UNZ_OK);
    free(szFileName);
    

    You should also investigate the meaning of the return value of unzGetCurrentFileInfo. If it fails, it’s unlikely you can use szFileName or any of the other arguments to the function – so don’t call NSLog with those variables if the function fails

    In this case, malloc seems unneccesary. Just use a local array, and drop the free() call.

    char szFileName[1024];
    uLong fileNameBufferSize = sizeof szFileName;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I need a function that will clean a strings' special characters. I do NOT
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
Does anyone know how can I replace this 2 symbol below from the string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.