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