utilities_linux.h - Biblioteca com diversas funções para o Linux
Publicado por Mauricio Ferrari (LinuxProativo) (última atualização em 03/05/2020)
[ Hits: 1.590 ]
Homepage: https://www.youtube.com/@LinuxProativo
Essa biblioteca possui métodos de funções para o Linux que eu encontrei na internet. Então juntei tudo e fiz algumas adaptações para ficar ao meu gosto.
/****************************************************************************************************
Biblioteca utilities_linux.h
By Mauricio Ferrari - 10/02/2020.
Funções Adaptadas dos Autores:
Fabio Junior Sabai - 29/11/2004
Marcos Paulo Ferreira - 27/12/2012
****************************************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <termios.h>
/****************************************************************************************************/
/** Defines. **/
#define getch() init_attr(1); _getch();
#define getche() init_attr(1); _getche();
#define kbhit() init_attr(0); _kbhit();
/****************************************************************************************************/
/** Declarações de Funções. **/
void rl_ttyset(int rst);
void init_attr(int x);
void close_attr();
int _getch(void);
int _getche(void);
int _kbhit(void);
static char *gets(char *str);
struct termios old_attr, new_attr;
/****************************************************************************************************/
/** rl_ttyset - Função Para Ler Teclas Pressionadas Pela Função getc sem Pressionar ENTER. **/
void rl_ttyset(int rst){
static struct termios old;
struct termios new;
if(rst==0){
(void) tcgetattr(0, &old);
new=old;
new.c_lflag &=~(ECHO|ICANON);
new.c_iflag &=~(ISTRIP|INPCK);
(void) tcsetattr(0, TCSANOW, &new);
}else{
(void) tcsetattr(0, TCSANOW, &old);
}
}
/****************************************************************************************************/
/** init_attr - Função para Desligar o Modo Canônico. **/
void init_attr(int x){
tcgetattr(0,&old_attr);
new_attr=old_attr;
new_attr.c_lflag &=~ICANON;
new_attr.c_cc[VTIME]=0;
new_attr.c_cc[VMIN]=x;
}
/****************************************************************************************************/
/** close_attr - Função para Restaurar o Modo Canônico. **/
void close_attr(){
tcsetattr(STDIN_FILENO,TCSANOW,&old_attr);
}
/****************************************************************************************************/
/** _getch - Implementação do getch no Linux. **/
int _getch(void){
int c;
new_attr.c_lflag &=~ECHO;
tcsetattr(STDIN_FILENO,TCSANOW,&new_attr);
c=getchar();
tcsetattr(STDIN_FILENO,TCSANOW,&old_attr);
return c;
}
/****************************************************************************************************/
/** _getche - Implementação do getche no Linux. **/
int _getche(void) {
int c ;
new_attr.c_lflag &=ECHO;
tcsetattr(STDIN_FILENO,TCSANOW,&new_attr);
c=getchar();
tcsetattr(STDIN_FILENO,TCSANOW,&old_attr);
return c;
}
/****************************************************************************************************/
/** _kbhit - Implementação do kbhit no Linux. **/
int _kbhit(void) {
int c;
tcsetattr(STDIN_FILENO,TCSANOW,&new_attr);
c=getchar();
tcsetattr(STDIN_FILENO,TCSANOW,&old_attr);
return c;
}
/****************************************************************************************************/
/** gets - Alguns Compiladores do Linux não Possuem mais o gets. **/
static char *gets(char *str){
int c;
int n=0;
while((c=getchar())!=EOF && c!='\n')
str[n++]=c;
str[n]='\0';
return n==0 && c==EOF? NULL: str;
}
/****************************************************************************************************/
Testar o melhor método de organização C (inserção, bolha e shell-sort)
Checkcred - Checagem de créditos.
Imprime a soma dos numeros positivos e negativos
Nenhum comentário foi encontrado.
O Editor de Texto Nano: Simplicidade no Terminal
SynapSeq - programa para estimular as ondas cerebrais
Por que seu __DIR__ falhou ou o "inferno" dos caminhos no PHP
Preparando-se para certificações da LPI através do LPI Lab
Migração de Arch Linux para repositórios CachyOS (Uso de Instruções v3 e v4)
Jogando "Magic" gratuitamente no Linux
Zoxide e fzf no bash para incrementar o uso do Terminal
As diferencas entre o clipboard comum e a selecao ativa
Arch Linux com repos do CachyOS para otimização ou usar Gentoo?
A falsa sensação de que entende a tal da palavra! (0)
Eu aprendi o segredo das artes! hahaha (2)
Como instalo o Clipper/Harbour no Linux Ubuntu (0)









