creat.c

来自「由3926个源代码」· C语言 代码 · 共 62 行

C
62
字号
/*--------------------------------------------------------------------*/
/*    C R E A T . C                                                   */
/*                                                                    */
/*    Support routines for UUPC/extended                              */
/*                                                                    */
/*    Changes Copyright 1990, 1991 (c) Andrew H. Derbyshire           */
/*                                                                    */
/*    History:                                                        */
/*       21Nov1991 Break out of lib.c                          ahd    */
/*--------------------------------------------------------------------*/

#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#ifndef __GNUC__
#include <io.h>
#endif

/*--------------------------------------------------------------------*/
/*                    UUPC/extended include files                     */
/*--------------------------------------------------------------------*/

#include "lib.h"
#include "hlib.h"

/*--------------------------------------------------------------------*/
/*    C R E A T                                                       */
/*                                                                    */
/*    Create a file with the specified mode                           */
/*--------------------------------------------------------------------*/

int CREAT(const char *name, const int mode, const char ftyp)
{

   char *last;
   char *path;
   int results;

   /* are we opening for write or append */
   FILEMODE(ftyp);
   results = creat(name, mode);

   if (results != -1)
      return results;

   /* see if we need to make any intermediate directories */
   path = normalize( name );

   if ((last = strrchr(path, '/')) != nil(char))
   {
      *last = '\0';
      MKDIR(path);
   }

   /* now try open again */
   return creat(name, mode);

} /*CREAT*/

⌨️ 快捷键说明

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