Changes between Version 3 and Version 4 of DevelopersFAQ


Ignore:
Timestamp:
Aug 5, 2007, 7:47:07 PM (17 years ago)
Author:
guest
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • DevelopersFAQ

    v3 v4  
    6868enough.
    6969
     70
     71=== Is the code below OK? Did I account for the terminating nulls correctly? ===
     72
     73{{{
     74//BldFullPathName returns the fullpath of a file or Nullstr
     75CHAR *FullPathName = BldFullPathName(CHAR *pathname, CHAR
     76*filename)
     77{
     78
     79CHAR newname[CCHMAXPATH] = Nullstr;
     80INT c = 0;
     81
     82c = strlen(pathname);
     83if (c > 0) {
     84memcpy(newname, pathname, c + 1);
     85if (newname[c] != '\\')
     86newname[c++] = '\\';
     87}
     88strcpy(newname + c, filename);
     89return newname;
     90}
     91
     92//BldQuotedFullPathName returns the quoted fullpath of a file or ""
     93CHAR *FullPathName = BldQuotedFullPathName(CHAR *pathname,
     94CHAR *filename)
     95{
     96
     97CHAR newname[CCHMAXPATH] = '\"';
     98INT c = 0;
     99
     100c = strlen(pathname);
     101if (c > 0) {
     102memcpy(newname + 1, pathname, c + 2);
     103if (newname[c + 1] != '\\')
     104newname[c + 2] = '\\';
     105strcpy(newname + c + 3, filename);
     106}
     107else
     108strcpy(newname + 1, filename)
     109strcat(newname, '\"')
     110return newname;
     111}
     112}}}
     113
     114Not quite. The caller must pass a pointer to the buffer. Keep in mind
     115that local variable disappear when the function returns.
     116
     117
     118{{{
     119PSZ BldFullPathName(PSZ fullPathName, PSZ dirname, PSZ filename);
     120}}}
     121
     122
     123
     124{{{
     125CHAR newname[CCHMAXPATH] = Nullstr;
     126}}}
     127
     128
     129This will give you an error because NullStr is a pointer.
     130
     131
     132{{{
     133CHAR newname[CCHMAXPATH];
     134}}}
     135
     136
     137Is sufficent since you are always going to copy something. The return is
     138
     139
     140{{{
     141return fullPathName
     142}}}
     143
     144
     145with the appropriate name changes.
     146
     147
     148{{{
     149//BldQuotedFullPathName returns the quoted fullpath of a file or "" CHAR
     150}}}
     151
     152
     153The quotes need to be optional and the return buffer needs to be passed as
     154above.
     155
     156
     157{{{
     158PSZ BldQuotedFullPathName(PSZ fullPathName, PSZ pathname, PSZ filename)
     159}}}
     160
     161
     162You also need to add the calls to needs_quotes() a stuff the quotes only
     163if needed. This is what the existing inline code does.
     164
    70165----