Changeset 3730
- Timestamp:
- Mar 18, 2011, 12:54:25 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/libc-0.6/src/emx/src/emxomf/emxomf.c
r2983 r3730 795 795 } 796 796 797 798 799 800 801 /* Put the string pszName into the current OMF record. 802 In the OMF record, the string is preceded by a length byte. The 803 string length must not exceed 255; if it is too long, display a 804 warning and truncate the string. Moreover, there must be enough 805 space left in the OMF record; if there isn't, display an error 806 message and abort. */ 807 808 static void put_nstr(const char *pszName, size_t cch) 797 /* Put the string pszName into the given buffer pOutBuf (which must be at least 798 256 bytes long). The string length must not exceed 255 bytes (OMF format 799 requirement); if it is too long, display a warning and truncate the string. 800 The string returned in pOutBuf is zero-terminated. The function returns the 801 length of the resulting string. */ 802 803 static int make_nstr (const char *pszName, size_t cch, char *pszOutBuf) 809 804 { 810 805 if ( cch > SYMBOL_MAX_LENGTH … … 824 819 assert(psz - &szHash[0] == SYMBOL_HASH_LENGTH); 825 820 826 if (!fits(1 + SYMBOL_MAX_LENGTH + SYMBOL_HASH_LENGTH)) 827 doesn_fit(); 828 out_data[out_idx++] = SYMBOL_MAX_LENGTH + SYMBOL_HASH_LENGTH; 829 memcpy(out_data + out_idx, pszName, SYMBOL_MAX_LENGTH); 830 out_idx += SYMBOL_MAX_LENGTH; 831 memcpy(out_data + out_idx, szHash, SYMBOL_HASH_LENGTH); 832 out_idx += SYMBOL_HASH_LENGTH; 821 memcpy(pszOutBuf, pszName, SYMBOL_MAX_LENGTH); 822 memcpy(pszOutBuf + SYMBOL_MAX_LENGTH, szHash, SYMBOL_HASH_LENGTH); 823 pszOutBuf[SYMBOL_MAX_LENGTH + SYMBOL_HASH_LENGTH] = '\0'; 833 824 834 825 warning ("Truncated symbol '%.*s' to '%.*s%s'", cch, pszName, SYMBOL_MAX_LENGTH, pszName, szHash); 826 827 cch = SYMBOL_MAX_LENGTH + SYMBOL_HASH_LENGTH; 835 828 } 836 829 else … … 838 831 assert(cch <= 0xff); 839 832 cch &= 0xff; 840 if (!fits(1+cch)) 841 doesn_fit(); 842 out_data[out_idx++] = (byte)cch; 843 memcpy(out_data+out_idx, pszName, cch); 844 out_idx += cch; 845 } 833 memcpy(pszOutBuf, pszName, cch); 834 pszOutBuf[cch] = '\0'; 835 } 836 return cch; 837 } 838 839 /* Put the string pszName into the current OMF record. 840 In the OMF record, the string is preceded by a length byte. The 841 string length must not exceed 255; if it is too long, display a 842 warning and truncate the string. Moreover, there must be enough 843 space left in the OMF record; if there isn't, display an error 844 message and abort. */ 845 846 static void put_nstr(const char *pszName, size_t cch) 847 { 848 char szName[256]; 849 850 cch = make_nstr(pszName, cch, szName); 851 852 if (!fits(1 + cch)) 853 doesn_fit(); 854 out_data[out_idx++] = (byte)cch; 855 memcpy(out_data+out_idx, szName, cch); 856 out_idx += cch; 846 857 } 847 858 … … 1200 1211 int i; 1201 1212 const char *pub_name; 1213 char szPubName[256]; 1214 int cchPubName; 1202 1215 1203 1216 for (i = 0; i < sym_count - 1; ++i) 1204 1217 if (sym_ptr[i].n_type == (N_INDR|N_EXT) && sym_ptr[i+1].n_type == N_EXT) 1205 1218 { 1219 pub_name = (const char *)(str_ptr + sym_ptr[i].n_un.n_strx); 1220 if (strip_underscore (pub_name)) 1221 ++pub_name; 1222 cchPubName = make_nstr (pub_name, strlen(pub_name), szPubName); 1223 1206 1224 init_rec (ALIAS); 1207 put_sym ((const char *)(str_ptr + sym_ptr[i].n_un.n_strx)); 1225 put_8 (cchPubName); 1226 put_mem (szPubName, cchPubName); 1208 1227 put_sym ((const char *)(str_ptr + sym_ptr[i+1].n_un.n_strx)); 1209 1228 write_rec (); … … 1211 1230 if (out_lib != NULL) 1212 1231 { 1213 pub_name = (const char *)(str_ptr + sym_ptr[i].n_un.n_strx); 1214 if (strip_underscore (pub_name)) 1215 ++pub_name; 1216 if (omflib_add_pub (out_lib, pub_name, mod_page, lib_errmsg) != 0) 1232 if (omflib_add_pub (out_lib, szPubName, mod_page, lib_errmsg) != 0) 1217 1233 error (lib_errmsg); 1218 1234 } … … 1248 1264 dword address; 1249 1265 char szName[256]; 1266 char szPubName[256]; 1267 int cchPubName; 1250 1268 1251 1269 started = FALSE; … … 1266 1284 if ( sym_ptr[i].n_type >= N_WEAKU && sym_ptr[i].n_type <= N_WEAKB ) 1267 1285 name = weak_process_name(&sym_ptr[i], name, szName, sizeof(szName)); 1286 pub_name = name; 1287 if (strip_underscore (pub_name)) 1288 ++pub_name; 1289 cchPubName = make_nstr (pub_name, strlen (pub_name), szPubName); 1268 1290 1269 1291 if ( out_lib != NULL … … 1274 1296 || sym_ptr[i].n_type == N_WEAKD ) ) 1275 1297 { 1276 pub_name = name; 1277 if (strip_underscore (pub_name)) 1278 ++pub_name; 1279 if (omflib_add_pub (out_lib, pub_name, mod_page, 1298 if (omflib_add_pub (out_lib, szPubName, mod_page, 1280 1299 lib_errmsg) != 0) 1281 1300 error (lib_errmsg); … … 1296 1315 started = TRUE; 1297 1316 } 1298 put_sym (name); 1317 put_8 (cchPubName); 1318 put_mem (szPubName, cchPubName); 1299 1319 if (big) 1300 1320 put_32 (address); … … 1331 1351 if (out_lib != NULL) 1332 1352 { 1353 /* Note! make_nstr is not needed here, main is too short. */ 1333 1354 if (omflib_add_pub (out_lib, name, mod_page, lib_errmsg) != 0) 1334 1355 error (lib_errmsg); … … 2412 2433 long ord, const char *mod) 2413 2434 { 2435 char szPubName[256]; 2436 int cchPubName; 2437 2414 2438 /* Skip a leading underscore character if present. */ 2415 2439 2416 2440 if (strip_underscore (pub_name)) 2417 2441 ++pub_name; 2442 cchPubName = make_nstr (pub_name, strlen (pub_name), szPubName); 2418 2443 2419 2444 /* Make the symbol public in the output library. */ 2420 2445 2421 if (omflib_add_pub (out_lib, pub_name, mod_page, lib_errmsg) != 0)2446 if (omflib_add_pub (out_lib, szPubName, mod_page, lib_errmsg) != 0) 2422 2447 error (lib_errmsg); 2423 2448 … … 2429 2454 put_8 (IMPDEF_SUBTYPE); 2430 2455 put_8 (proc_name == NULL ? 0x01 : 0x00); /* Import by ordinal or by name */ 2431 put_str (pub_name); /* Underscore already removed above */ 2456 put_8 (cchPubName); 2457 put_mem (szPubName, cchPubName); 2432 2458 put_str (mod); 2433 2459 if (proc_name == NULL) … … 2435 2461 else if (strcmp (proc_name, pub_name) == 0) 2436 2462 put_8 (0); 2437 else 2463 else { 2438 2464 put_str (proc_name); 2465 } 2439 2466 write_rec (); 2440 2467 init_rec (MODEND|REC32);
Note:
See TracChangeset
for help on using the changeset viewer.