[완료]바이너리 파일(예;실행파일등)을 다른 디렉토리에 복사 할려면....

kimyh의 이미지

실행파일같은 애스키가 아닌 바이너리 파일을 다른 디렉토리에 복사 할려면 어떻게 하는지요.
애스키 코드로 된 확장자가 .txt나 .c 또는 .cpp 같은 파일들은 아래와 같이 하면 별 문제가 없는데
바이너리 파일은 어떻게 하는지 모르겠군요.

검색을 해도 찾지를 못해서요...

애스키코드 파일 카피
if((member_df = fopen("ipdns.txt", "r")) == NULL);
fseek(member_df, 0L, 0);
ret = fread(contents, 1, buffsize[BUFSIZ], member_df);
fclose(member_df);

member_df = fopen("testcopy/ipdns.txt", "w");
fprintf(member_df, "%s", contents);
fclose(member_df);

위와 같이 하면 testcopy디렉토리 아래 ipdns.txt 라는파일을 복사 할수 있는데 바이너리 파일은 어떻게
처리 하는지 모르겠군요.
아시는분 도움 주시면 감사하겠습니다.

bushi의 이미지

바이너리 파일을 대상으로 똑같이 시도해보고,
안되면 같이 고민해보지요.

kimyh의 이미지

bushi님 답변 주신것 감사 합니다.
질문과 같은 방법으로는 되지않고요
아래와 같이 해서 처리 하였습니다.

	void	fatal(char *);
	int	source, object;
	int	read_number;
	char	buff[BUFSIZ];
 
	if((source = open("ipdns", O_RDONLY)) < 0)
		fatal("read open");
	if((object = open("/testcopy/ipdns", O_WRONLY | O_CREAT | O_TRUNC, PERMS)) < 0)
		fatal("write open");
	while((read_number = read(source, buff, BUFSIZ)) > 0)
		{
		if(write(object, buff, read_number) < read_number)
			{
			close(source);
			close(object);
			exit(1);
			}
		}
	close(source);
	close(object);

=========================================================================
살며 그리고 사랑하며...
정보는 공유할때 그 가치가 있는것.....
나의 조그만 지식공유는 남에게 엄청난 기쁨을 안겨 준다.

살며 그리고 사랑하며...
정보는 공유할때 그 가치가 있는것.....
나의 조그만 지식공유는 남에게 엄청난 기쁨을 안겨 준다.

bushi의 이미지

제가 좀 성급했습니다.
OS 가 무엇인지 여쭤볼 것을...

fopen(..., "rb");
fopen(..., "wb");

처럼 해도 안된다면 ... 쉽게 접할 수 있는 놈은 아니겠습니다.

kimyh의 이미지

지금이 새벽 2시인데 주무시지 않고 정말 열심이시군요.
답변 주셔서 감사합니다.

fopen(..., "rb");
fopen(..., "wb");

이런식으로도 파일을 열고 쓰는 방법도 있군요.
공부삼아 시도 해 보겠습니다.

좋은 정보 다시 한번 감사드립니다.
========================================================

살며 그리고 사랑하며...
정보는 공유할때 그 가치가 있는것.....
나의 조그만 지식공유는 남에게 엄청난 기쁨을 안겨 준다.

살며 그리고 사랑하며...
정보는 공유할때 그 가치가 있는것.....
나의 조그만 지식공유는 남에게 엄청난 기쁨을 안겨 준다.

bushi의 이미지

잠을 안자고 뭘 한다기보다는...
잠을 잘 수 없을 정도로 뭐가 잘 안풀린다는게 맞습니다.
CPU 가 새로 왔는데.. 맨 땅에 헤딩 수준은 아니지만 부실한 매뉴얼 부터 시작해서 뭐하나 마음에 드는 게 없네요.

원문을 보면

man wrote:

The mode string can also include the letter ‘‘b’’ either as a last
character or as a character between the characters in any of the two-
character strings described above. This is strictly for compatibility
with ANSI X3.159-1989 (‘‘ANSI C’’) and has no effect; the ‘‘b’’ is
ignored on all POSIX conforming systems, including Linux
. (Other sys-
tems may treat text files and binary files differently, and adding the
`‘b’’ may be a good idea if you do I/O to a binary file and expect that
your program may be ported to non-Unix environments.)

댓글 달기

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