diff --git a/include/support.h b/include/support.h index df5766aea..f1ee02fd8 100644 --- a/include/support.h +++ b/include/support.h @@ -80,4 +80,33 @@ static inline bool is_power_of_2(Bitu val) { * For more info see https://graphics.stanford.edu/~seander/bithacks.html#DetermineIfPowerOf2*/ } +/// Copy a string into C array +/// +/// This function copies string pointed by src to fixed-size buffer dst. +/// At most N bytes from src are copied, where N is size of dst. +/// If exactly N bytes are copied, then terminating null byte is put +/// into buffer, thus buffer overrun is prevented. +/// +/// Function returns pointer to buffer to be compatible with std::strcpy. +/// +/// Usage: +/// +/// char buffer[2]; +/// safe_strcpy(buffer, "abc"); +/// // buffer is filled with "a" + +template +char * safe_strcpy(char (& dst)[N], const char * src) noexcept { + snprintf(dst, N, "%s", src); + return & dst[0]; +} + +template +char * safe_strcat(char (& dst)[N], const char * src) noexcept { + strncat(dst, src, N - strnlen(dst, N) - 1); + return & dst[0]; +} + +#define safe_strncpy(a,b,n) do { strncpy((a),(b),(n)-1); (a)[(n)-1] = 0; } while (0) + #endif diff --git a/src/dosbox.cpp b/src/dosbox.cpp index d068cd41f..15e8e0035 100644 --- a/src/dosbox.cpp +++ b/src/dosbox.cpp @@ -2796,6 +2796,9 @@ void DOSBOX_SetupConfigSections(void) { Pmulti_remain->GetSection()->Add_string("parameters",Property::Changeable::WhenIdle,""); Pmulti_remain->Set_help("see serial1"); + Pstring = secprop->Add_path("phonebookfile", Property::Changeable::OnlyAtStart, "phonebook-" VERSION ".txt"); + Pstring->Set_help("File used to map fake phone numbers to addresses."); + // printer redirection parameters secprop = control->AddSection_prop("printer", &Null_Init); Pbool = secprop->Add_bool("printer", Property::Changeable::WhenIdle, true); diff --git a/src/hardware/serialport/serialport.cpp b/src/hardware/serialport/serialport.cpp index 87c73e607..4a1644dc2 100644 --- a/src/hardware/serialport/serialport.cpp +++ b/src/hardware/serialport/serialport.cpp @@ -1337,6 +1337,11 @@ public: // COM1 is a 8251 UART, while COM2 and higher if they exist are 8250/16xxx UARTs if (IS_PC98_ARCH) return; +#if C_MODEM + const Prop_path *pbFilename = section->Get_path("phonebookfile"); + MODEM_ReadPhonebook(pbFilename->realpath); +#endif + char s_property[] = "serialx"; for(Bit8u i = 0; i < 4; i++) { // get the configuration property diff --git a/src/hardware/serialport/softmodem.h b/src/hardware/serialport/softmodem.h index 4a5751a97..ec860408d 100644 --- a/src/hardware/serialport/softmodem.h +++ b/src/hardware/serialport/softmodem.h @@ -50,6 +50,8 @@ enum ResTypes { #define TEL_CLIENT 0 #define TEL_SERVER 1 +bool MODEM_ReadPhonebook(const std::string &filename); + class CFifo { public: CFifo(Bitu _size) { @@ -166,9 +168,9 @@ public: void EnterIdleState(); void EnterConnectedState(); - + void openConnection(void); - bool Dial(char * host); + bool Dial(const char *host); void AcceptIncomingCall(void); Bitu ScanNumber(char * & scan); char GetChar(char * & scan);