mingw 는 file i/o가 안되는지요?

chocokeki의 이미지

리눅스와 윈도우 10의 bash에서 돌아가는 프로그램이 있는데요
이 프로그램을 윈도우용으로 포팅하려고 합니다

별 프로그램은 아니고 stat이랑 open, read, write 몇 번 호출하는 간단한 프로그램 입니다

그런데 mingw 에서 stat, read 같은 함수가 return 을 -1로 합니다
퍼미션 문제인가 싶어 관리자 권한으로 실행해봤는데도 동일하네요

혹시 아시는지요?

라스코니의 이미지

file path를 어떻게 주셨나요?

chocokeki의 이미지

먼저 올렸던 질문은 경로 때문에 생기는 문제였습니다.
eclipse에서 디버그 모드로 실행하면 실행파일이 있는 위치가 경로로 잡히지 않고 프로젝트 로드한 디렉토리가 경로로 잡히네요

그리고 이번에는 317KB 정도 하는 바이너리를 open 후 read하면 474B 만 읽히고 0를 리턴하는 문제가 있습니다.

1B씩 반복해서 읽거나 루프를 돌려놔도 무조건 474B 만 읽고 0를 리턴하네요
474B는 내용을 비교해보면 잘 읽는 것 같습니다. 왜 이럴까요?
(코드는 별거 없습니다)

int rb;
int fd = open(fname, O_RDONLY);
if(fd <= 0) {
    return -1;
}
 
for(len=0, rb=1; len<file_length && rb>0; len++)
{
    rb = read(fd, buf + len, 1);
}

-> 실행하면 len은 474 가 나옴
익명 사용자의 이미지

코드가 일부분 뿐이라서 확실하진 않지만

file_length 값이 474 일것 같아 보이네요.
file_length 값을 먼저 확인해보세요.

chocokeki의 이미지

제가 코드를 이상하게 짜서 분란이 발생하고 있군요
죄송합니다

errno는 발생되지 않습니다(항상 0이상의 정수만 리턴)
딜레이를 넣어도 마찬가지네요 웃긴게 stat의 filesize는 정확하게 읽습니다.

mingw가 이상하다고 판단하여 플랫폼을 옮겼습니다
저 루프코드는 신경쓰지 마세요 제가 봐도 별로 안 좋게 짜여진 거 같습니다

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.