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

  • Home
  • SEARCH
  • 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 323113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:00:03+00:00 2026-05-12T09:00:03+00:00

basename(3) and dirname(3) can split an absolute path into its respective components. Short of

  • 0

basename(3) and dirname(3) can split an absolute path into its respective components.

Short of using snprintf(3), is there a natural posix-compliant library call that does the inverse – takes a directory and a filename and concatenates them?

Manually concatenation works fine for me, but can get a little tedious at times.

  • 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-12T09:00:04+00:00Added an answer on May 12, 2026 at 9:00 am

    as far I know there is no such function in POSIX. However in the GNU libc manual there is a nice helper function:

    char *concat (const char *str, ...)
      {
       va_list ap;
       size_t allocated = 100;
       char *result = (char *) malloc (allocated);
    
       if (result != NULL)
         {
           char *newp;
           char *wp;
    
           va_start (ap, str);
    
           wp = result;
           for (s = str; s != NULL; s = va_arg (ap, const char *))
             {
               size_t len = strlen (s);
    
               /* Resize the allocated memory if necessary.  */
               if (wp + len + 1 > result + allocated)
                 {
                   allocated = (allocated + len) * 2;
                   newp = (char *) realloc (result, allocated);
                   if (newp == NULL)
                     {
                       free (result);
                       return NULL;
                     }
                   wp = newp + (wp - result);
                   result = newp;
                 }
    
               wp = mempcpy (wp, s, len);
             }
    
           /* Terminate the result string.  */
           *wp++ = '\0';
    
           /* Resize memory to the optimal size.  */
           newp = realloc (result, wp - result);
           if (newp != NULL)
             result = newp;
    
           va_end (ap);
         }
    
       return result;
     }
    

    usage:

    const char *path = concat(directory, "/", file);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm currently using File::Basename fileparse to separate out a file's directory, base file name
I am using cherrypy as a server. This server gives you ability to download
I have script wherein basename() is used 100-1000s of time, I was just thinking
If I call: http://localhost/info/imgfeed.php?img=deer.png in the IE address bar then it is displayed fine.
I'm new to Python so forgive me if this is basic, I've searched but
Currently FTP is insanely slow on our server when it comes to multiple small
Currently FTP is insanely slow on our server when it comes to multiple small
I wrote a Facebook app from PHP and HTML that work perfect in the
I keep getting an error when I try to include simpletest in my include_path:
I wrote a Facebook app in PHP and need to be able to allow

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.