터미널을 수정하는 C코드 이해가 안되서 여쭈고 싶습니다..

ngw2833의 이미지

패스워드 프로그램을 만드는 코드 예제를 실습해보고 있습니다..

termios 구조체 두 개 만들고 (initialresettings, newresettings)

tcgetattr(fileno(stdin), &inialresettings);
으로 현재 터미널 세팅 불러오고

newresettings = initialresettings;
newresettings.C_lflag = ~ECHO
으로 newresettings 변수에 현재 터미널 세팅값 넣고 ECHO 해제하는 것 까지는 어떻게 이해를 했는데

if(tcsetattr(fileno(stdin), TCSAFLUSH, &newresettings) != 0)
이 구문이 뭘 말하는 지 모르겠어요.
tcsetattr함수가 지정된 파일 디스크럽터에 쓰는 역할이라고 설명을 보았는데도,
잘 이해가 안되네요..

그리고 두 함수, tcgetattr, tcsetattr에 들어가는 fileno(stdin)이 무엇인지.. 모르겠습니다..ㅠ

조금만 도움을 주실 수 있을까요.

File attachments: 
첨부파일 크기
Image icon 1.png34.13 KB
raymundo의 이미지

http://database.sarang.net/study/glibc/12.htm

여기 12.4.2를 보시면 될 것 같은데요. 구문 자체야 터미널에 newresettings 에 지정된 속성을 적용하되, 현재 입출력 중인 데이터가 있다면 새 속성을 곧바로 적용할지(입출력 중인 데이터에도 영향을 끼치도록) 아니면 그 입출력이 끝난 다음에 새 속성을 적용할지를 두번째 인자로 지정해준다는 말 같네요. 저도 직접 해본 게 아니라 구체적인 예를 들지는 못하겠습니다만...

fileno() 는 FILE * 구조체를 인자로 받아서 해당 파일스트림의 파일기술자 번호(file descriptor, int 형)를 반환하는 함수입니다. 고수준 입출력(fopen, fread, fclose...)에서는 FILE 포인터가 가리키는 FILE 구조체를 사용하여 스트림을 지정하지만 저수준 입출력(open, read, close 등)에서는 파일기술자를 사용하니까요. stdin 을 인자로 받으면 보통은(아마도 언제나) 0을 반환하겠죠. 표준 출력은 1, 표준 에러는 2.

좋은 하루 되세요!

ngw2833의 이미지

저도 그 글 읽으면서 해보고 있어요 ㅎ.
부가적인 설명 감사합니다..! ㅎㅎ

남관우

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.