⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cpnt.c

📁 The Offline NT Password Editor (c) 1997-2004 Petter Nordahl-Hagen
💻 C
字号:
/* * cpnt.c - Copy over file without truncating. *          For use on my current floppy, since it's 'cp' insist *          on truncating first, and NTFS doesn't like that yet. * * 2003-apr: First version * * * Copyright (c) 1997-2003 Petter Nordahl-Hagen. * Freely distributable in source or binary for noncommercial purposes, * but I allow some exceptions to this. * Please see the COPYING file for more details on * copyrights & credits. *   * THIS SOFTWARE IS PROVIDED BY PETTER NORDAHL-HAGEN `AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * */ #include <stdio.h>#include <stdlib.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <errno.h>#include <string.h>#include <unistd.h>#define BUFSIZE 16384int main(int argc, char **argv){  void *buf;  int sf,df,rb,wb;  int going = 1;  int e = 0;  if (argc != 3) {    printf("usage: cpnt <sourcefile> <destfile>\n");    printf("       sorry, only one file at a time yet.\n");    return(1);  }#if 0  printf("input : %s\n",argv[1]);  printf("output: %s\n",argv[2]);#endif  buf = malloc(BUFSIZE);  if (!buf) {    printf("cpnt: could not allocate buffer\n");    return(1);  }  sf = open(argv[1],O_RDONLY);  if (sf < 0) {    e = errno;    printf("cpnt: %s: %s\n",argv[1],strerror(e));    return(1);  }  df = open(argv[2],O_WRONLY|O_CREAT,00666);  if (df < 0) {    e = errno;    printf("cpnt: %s: %s\n",argv[2],strerror(e));    return(1);  }  while (going) {    rb = read(sf,buf,BUFSIZE);    if (rb < 0) {      e = errno;      printf("cpnt: error while reading: %s\n",strerror(e));      going = 0;      break;    }    if (rb == 0) going = 0;    wb = write(df,buf,rb);    if (wb < 0) {      e = errno;      printf("cpnt: error while writing: %s\n",strerror(e));      going = 0;    }      }  close(sf);  close(df);  free(buf);  return(e ? 1 : 0);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -