In Windows, I can use GetAPC function to get the local codepage. But how should I do to get local codepage in Linux? Thanks. Answer Linux does not use code page identifiers. It has locale identifiers, but different processes can have different locales and a process may be using different locales in different categories at once. Every C program starts
Tag: c++
Adding newline character to printf() changes code behaviour
For some reason, adding n to printf() changes the behaviour of below code. The code without n prints (null) whereas the code with n leads to Segmentation fault. Printf.c Printf.c – Output Printf_Newline.c Printf_Newline.c – Output I am curious to understand the reason behind this. Answer Both are undefined behavior, so an answer could stop right here. But there’s at
In the kernel space, how does one get the physical addresses corresponding to a file on ext4-formatted disk
If you’re here: https://github.com/torvalds/linux/blob/master/fs/ext4/file.c#L360 You have access to these two structs inside the ext4_file_mmap function: I am changing the implementation of this function for dax mode so that the page tables get entirely filled out for the file the moment you call mmap (to see how much better performance not taking any pagefaults gives us). I have managed to get
OpenSSL will not release file handles
I am writing a service (in C for CentOS) that must make lots of outbound SSL connections to a third party REST API via SSL. OpenSSL is used to create establishment of the secure connections with the remote server. After initialization of the ssl_connection I register the returned file descriptor with our epoll queue. I can connect and perform the
getnameinfo() compile time error – Extracting MAC address in Linux
I have to send to the server the IP address and MAC address of the network interface from which my client socket is connected and communicating with the server. All machines are on intra-net. I have extracted the IP of my socket and I am attempting to extract the H/W address. My strategy : Extract IP of the socket using
g++ can’t link curl lib files
I’m having some issues with getting g++ to link the curl lib files. I’m using Visual Studio 2017 with the linux dev plugin and Ubuntu Server 17.04. curl-config –libs gave an output of -Lcurl which I tried adding to the linker options in Project settings > Linker > Command Line > Additional options. I also added the –cflags output to
no such file or directory after redirection – simple command line program
Im programming a shell. This is a small piece of it that handles redirects. I only included the snippet that is causing the error. This portion of the program is supposed to take a command/argument line and execute the line accordingly. The wc < junk > junk2 is an example of a command line input and for some reason when
How I can find out if a Linux system uses Wayland or X11?
Used language I am using C++14 with cmake for my program. Problem: I would like to know how I can find out if a Linux system uses Wayland or X11 as a window system to be able to use both APIs in my source code without conflict. Thus creating a window with Wayland when Wayland is available and otherwise use
string to long, not giving me the correct answer
I am trying to convert number stored in the c string to long int. But I am not getting the expected output: Output : 821493369 gcc version 4.4.7 20120313 (Red Hat 4.4.7-16) Can you please advise what am I doing wrong here? Thanks. Answer In addition to using long long, you can use exact width types from stdint.h. For instance,
Using a signal handler to process datas received from a fifo
I am writing a simple client/server communication with fifo but i am stuck at using a signal handler to process client request. The server open a fifo in readonly and non blocking mode, read datas received and writes back some datas to the client fifo. And this actually works fine when there is no signal handler on the server side.