C 语言 ioctl

/*
*@author cody
*@date 2014-08-12
*@description 
*/
/*
#include <sys/ioctl.h>

send control and config order to device

int ioctl(int d,int request,...);
params
    d -- file descriptor
    request ---ioctl order

*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/ioctl.h>
void GetTernimalSize(){

    struct winsize size;
    if(isatty(STDOUT_FILENO) == 0){
        exit(1);
    }
    if(ioctl(STDOUT_FILENO,TIOCGWINSZ,&size) < 0){
        perror("ioctl error");
        exit(1);
    }

    printf("%d rows,%d columns\n",size.ws_row,size.ws_col );
}


int main(int argc, char const *argv[])
{
    GetTernimalSize();
    return 0;
}

 

posted @ 2014-08-12 14:42  誑逩の蝸犇  阅读(1121)  评论(0编辑  收藏  举报