ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

makepath_s.c
Go to the documentation of this file.
00001 /*
00002  * PROJECT:     ReactOS CRT library
00003  * LICENSE:     See COPYING in the top level directory
00004  * FILE:        lib/sdk/crt/stdlib/makepath_s.c
00005  * PURPOSE:     Creates a path
00006  * PROGRAMMERS: Wine team
00007  *              Copyright 1996,1998 Marcus Meissner
00008  *              Copyright 1996 Jukka Iivonen
00009  *              Copyright 1997,2000 Uwe Bonnes
00010  *              Copyright 2000 Jon Griffiths
00011  *
00012  */
00013 
00014 #include <precomp.h>
00015 #include <stdlib.h>
00016 #include <string.h>
00017 
00018 /*********************************************************************
00019  *      _makepath_s (MSVCRT.@)
00020  *
00021  * Safe version of _makepath.
00022  */
00023 int CDECL _makepath_s(char *path, size_t size, const char *drive,
00024                       const char *directory, const char *filename,
00025                       const char *extension)
00026 {
00027     char *p = path;
00028 
00029     if (!path || !size)
00030     {
00031         *_errno() = EINVAL;
00032         return EINVAL;
00033     }
00034 
00035     if (drive && drive[0])
00036     {
00037         if (size <= 2)
00038             goto range;
00039 
00040         *p++ = drive[0];
00041         *p++ = ':';
00042         size -= 2;
00043     }
00044 
00045     if (directory && directory[0])
00046     {
00047         size_t len = strlen(directory);
00048         unsigned int needs_separator = directory[len - 1] != '/' && directory[len - 1] != '\\';
00049         size_t copylen = min(size - 1, len);
00050 
00051         if (size < 2)
00052             goto range;
00053 
00054         memmove(p, directory, copylen);
00055 
00056         if (size <= len)
00057             goto range;
00058 
00059         p += copylen;
00060         size -= copylen;
00061 
00062         if (needs_separator)
00063         {
00064             if (size < 2)
00065                 goto range;
00066 
00067             *p++ = '\\';
00068             size -= 1;
00069         }
00070     }
00071 
00072     if (filename && filename[0])
00073     {
00074         size_t len = strlen(filename);
00075         size_t copylen = min(size - 1, len);
00076 
00077         if (size < 2)
00078             goto range;
00079 
00080         memmove(p, filename, copylen);
00081 
00082         if (size <= len)
00083             goto range;
00084 
00085         p += len;
00086         size -= len;
00087     }
00088 
00089     if (extension && extension[0])
00090     {
00091         size_t len = strlen(extension);
00092         unsigned int needs_period = extension[0] != '.';
00093         size_t copylen;
00094 
00095         if (size < 2)
00096             goto range;
00097 
00098         if (needs_period)
00099         {
00100             *p++ = '.';
00101             size -= 1;
00102         }
00103 
00104         copylen = min(size - 1, len);
00105         memcpy(p, extension, copylen);
00106 
00107         if (size <= len)
00108             goto range;
00109 
00110         p += copylen;
00111     }
00112 
00113     *p = '\0';
00114     return 0;
00115 
00116 range:
00117     path[0] = '\0';
00118     *_errno() = ERANGE;
00119     return ERANGE;
00120 }

Generated on Sat May 26 2012 04:35:35 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.