Internals of ncurses: console input [closed] - c

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
How exactly does Ncurses capture input into the console? I would like to implement it myself instead of using ncurses due to the overhead that ncurses is causing.
Thanks!

Very short and basically: It might use the TTY ioctl calls to get and set flags needed for the different modes. Then it could simply use read to read characters in a blocking or non-blocking manner.
Special keys (like the function keys for example) are read using multiple characters which are parsed.

Related

What is the special macro of buffer size in standard C library? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I saw this special macro when I read a source code. If I remember correctly, it is defined in the standard library.
The name of this macro is related to the buffer size, and in my machine its implementation is 1024.
Now I want to use it to initialize the buffer but I forgot what it is called.
So is there any one who can help me make my code look more professional?
If I don't know what I am looking for specifically, how can I clearly say what I need?
Are you talking about BUFSIZ? It's a macro provided by <stdio.h> and it expands to the size of the buffer used by setbuf().
I'm not sure what use it has in your own code.

Character functions vs string functions [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I just found a short code here, which would detect blank lines in a file. It used fgets() function in C library.
I wonder if character functions are better suited for files which have tabs, and perhaps continous spaces.
My qustion is what is the best way to parse a file for blank lines?
You can also use scanf(" %[^\n]s",string); in order to read spaces but fgets is best solution for your case.

reading configuration files [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I need the most efficient (performance/speed wise) way for reading a configuration from a file in C under linux.
I have not decided on the config format yet, but I would prefer (I'm all ears for better formats) the following format:
buttons 3
size 100
etc.
(The option name then the option value delimited by whitespace)
How can I read the options, should I go for strcmp? Or should I go for character by character manual comparison? Is there a more efficient way?
I want the program to:
be as quick as possible (time)
use as little cpu time as possible
use as little memory as possible
This code will be written for Linux (generic)
So far I'm using: xtest, stdio, stdlib and string libraries
I would rather code everything myself than use external libraries (which are not part of most Linux distributions).
Write/Read binary data for performance.
struct config { /* whatever */ };
struct config config;
configread(&config, "configfile"); // fread() or read() or whatever()
configwrite(&config, "configfile"); // fwrite() or write() or whatever()

Interpreting a shellcode [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am calling a shellcode using buffer overflow to spawn a root shell. Can somebody explain what this shellcode exactly does? I have tried different shellcodes to spawn a root shell, but this was the only one which worked for me.
\x31\xdb\x89\xd8\xb0\x17\xcd\x80\x31\xdb
\x89\xd8\xb0\x2e\xcd\x80\x31\xc0\x50\x68
\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89
\xe3\x50\x53\x89\xe1\x31\xd2\xb0\x0b\xcd
\x80
On first glance, the code appears to do setuid(0), then setgid(0), then call sys_execve() on some values (which include ASCII codes for "/bin//sh").
Looks like this is pure "payload" code, since I don't see anything to ensure the code is executed on the first place (buffer overflow, stack smashing, etc.).
(Thanks to #Hans Lub for the disassembler link)

How to redirect the output of a c code to a text file using another c code [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a c code file (let's say A). I wanted to redirect the output of that code to a text file by using another C program (say B). But the thing is I can't touch (edit) the A file. Is there a way to do so by using FILE operations, maybe?
You have two options here:
Probably the easiest, yet least flexible solution would using system function:
system("A.exe <someargs> > filename.txt");
If you want more flexibility, you should look into your platform APIs. On Windows, you can use CreateProcess specifying a handle to which redirect each of the streams (stdin, stdout and stderr).
http://msdn.microsoft.com/en-us/library/windows/desktop/ms682499%28v=vs.85%29.aspx

Resources