本文整理汇总了C++中create_file函数的典型用法代码示例。如果您正苦于以下问题:C++ create_file函数的具体用法?C++ create_file怎么用?C++ create_file使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了create_file函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: write_device_alias
int write_device_alias(const char *src, const char *dst, const char *alias)
{
char filename[PATH_MAX + 1];
create_name(filename, PATH_MAX, STORAGEDIR, src, "aliases");
create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
return textfile_put(filename, dst, alias);
}
开发者ID:cm-m3s,项目名称:m3s_opensource_files,代码行数:10,代码来源:storage.c
示例2: create_fd
int create_fd(const char *arg, int is_output, enum proto *proto, char *name, size_t max_name_size)
{
if (strncmp(arg, "udp:", 4) == 0 || strncmp(arg, "UDP:", 4) == 0) {
*proto = UDP;
arg += 4;
} else if (strncmp(arg, "tcp:", 4) == 0 || strncmp(arg, "TCP:", 4) == 0) {
*proto = TCP;
arg += 4;
} else if (strncmp(arg, "file:", 5) == 0) {
*proto = File;
arg += 5;
} else if (strncmp(arg, "eth:", 4) == 0) {
*proto = Eth;
arg += 4;
} else if (strcmp(arg, "null:") == 0) {
*proto = File;
arg = "/dev/null";
} else if (strcmp(arg, "zero:") == 0) {
*proto = File;
arg = "/dev/zero";
} else if (strcmp(arg, "stdin:") == 0) {
*proto = StdIn;
arg = "stdin";
} else if (strcmp(arg, "stdout:") == 0) {
*proto = StdOut;
arg = "stdout";
} else if (strcmp(arg, "stderr:") == 0) {
*proto = StdErr;
arg = "stderr";
} else if (strchr(arg, ':') != 0) {
*proto = UDP;
} else if (strcmp(arg, "-") == 0) {
*proto = is_output ? StdOut : StdIn;
arg = is_output ? "stdout" : "stdin";
} else {
*proto = File;
}
if (name != 0)
strncpy(name, arg, max_name_size);
switch (*proto) {
case UDP :
case TCP : return create_IP_socket(arg, is_output, *proto);
case File : return create_file(arg, is_output);
case Eth : return create_raw_eth_socket(arg, is_output);
case StdIn :
case StdOut:
case StdErr : return create_stdio(is_output, *proto);
default : fprintf(stderr, "Cannot create fd for unknown proto %d\n", *proto), exit(1);
}
}
开发者ID:saiyanprince,项目名称:pyimager,代码行数:55,代码来源:common.c
示例3: syscall_creat
int syscall_creat(const char *path, mode_t mode)
{
int i, drive;
int curdir_handle, new_handle;
char name_comp[13], conv_name[11], dir_path[501];
if (strlen(path) > 500) return ELONGPATH;
parse_path(path, &drive, dir_path, name_comp);
if (dir_path[0] != 0)
{
curdir_handle = open_path(drive, dir_path);
if (curdir_handle < 0)
return curdir_handle; // Error
}
else
{
curdir_handle = get_curdir_handle(drive);
increment_ref_count(curdir_handle);
}
// Last file name component.
if (convert_name(name_comp, conv_name) < 0)
{
close_dir(curdir_handle);
return EINVALIDNAME; // Error
}
mode = mode & 0x3f; // Valid bits
if (mode == 0) mode = 0x20;
else mode = mode & (~(FTYPE_DIR | FTYPE_VOLUME));
new_handle = create_file(curdir_handle, conv_name, mode);
close_dir(curdir_handle);
for (i=3; i<20; i++)
{
if (fileinf->fhandles[i] < 0)
break;
}
if (i < 20)
{
fileinf->fhandles[i] = new_handle;
new_handle = i;
}
else
{
close_file(new_handle);
new_handle = ENO_FREE_FILE_TABLE_SLOT;
}
return new_handle; // may be failure or success
}
开发者ID:sunank200,项目名称:ATOM-OS,代码行数:54,代码来源:fscalls.c
示例4: test_symlink
static int test_symlink(void)
{
char buf[1024];
const char *data = testdata;
int datalen = testdatalen;
int linklen = strlen(testfile);
int err = 0;
int res;
start_test("symlink");
res = create_file(testfile, data, datalen);
if (res == -1)
return -1;
unlink(testfile2);
res = symlink(testfile, testfile2);
if (res == -1) {
PERROR("symlink");
return -1;
}
res = check_type(testfile2, S_IFLNK);
if (res == -1)
return -1;
err += check_mode(testfile2, 0777);
err += check_nlink(testfile2, 1);
res = readlink(testfile2, buf, sizeof(buf));
if (res == -1) {
PERROR("readlink");
err--;
}
if (res != linklen) {
ERROR("short readlink: %u instead of %u", res, linklen);
err--;
}
if (memcmp(buf, testfile, linklen) != 0) {
ERROR("link mismatch");
err--;
}
err += check_size(testfile2, datalen);
err += check_data(testfile2, data, 0, datalen);
res = unlink(testfile2);
if (res == -1) {
PERROR("unlink");
return -1;
}
res = check_nonexist(testfile2);
if (res == -1)
return -1;
if (err)
return -1;
success();
return 0;
}
开发者ID:daddy366,项目名称:anarchy-fuse,代码行数:54,代码来源:test.c
示例5: save_fournisseur
void save_fournisseur(char* filename, Fournisseur* fournisseur) {
// Avant tout, tester si fournisseur n'est pas NULL
if (!fournisseur) return;
// Créer le fichier s'il n'existe pas
if (!file_exist(filename)) create_file(filename);
// Cherche si le médicament existe
// Si oui, il suffit de modifier le médicament
// Existant, Sinon on crée un nouveau médicament
// Dans la base de donnée
FILE* file = fopen(filename, "r+b");
// Sortir si le fichier ne peux pas s'ouvrir
if (!file) return;
// Itérer
do {
Fournisseur* current_fournisseur = (Fournisseur*)malloc(sizeof(Fournisseur));
if (!fread(current_fournisseur, sizeof(Fournisseur), 1, file)) break;
// Si le médicament est trouvé
if (current_fournisseur -> fournisseur_id == fournisseur -> fournisseur_id) {
// Modifier le médicament
long int currPost = ftell(file);
fseek(file, currPost - sizeof(Fournisseur), SEEK_SET);
fwrite(fournisseur, sizeof(Fournisseur), 1, file);
// Sortir de la fonction
fclose(file);
return;
}
} while (1);
// Trouver le dernier client ajouté
Fournisseur* last_fournisseur = get_last_fournisseur(filename);
// Set nouveau id
int new_id = (last_fournisseur == NULL) ? 1 : last_fournisseur -> fournisseur_id + 1;
// Set nouveau id
fournisseur -> fournisseur_id = new_id;
// Sauvegarder la commande
fwrite(fournisseur, sizeof(Fournisseur), 1, file);
// Fermer le fichier
fclose(file);
}
开发者ID:salimbraksa,项目名称:PharmAppMakeFile,代码行数:54,代码来源:fournisseur_controller.c
示例6: output_key
void output_key(char filename[], unsigned char key[], int key_size) {
// http://stackoverflow.com/a/8004250
if (strcmp(filename, "-") != 0) {
FILE *out = create_file(filename);
fwrite(key, key_size, 1, out);
fclose(out);
} else {
fwrite(bytes_to_hex(key, key_size), key_size * 2, 1, stdout);
fputs("\n", stdout);
}
}
开发者ID:sbp,项目名称:tweetnacl-tools,代码行数:11,代码来源:tweetnacl-keypair.c
示例7: setup
/***************************************************************
* setup() - performs all ONE TIME setup for this test.
***************************************************************/
void setup()
{
tst_sig(NOFORK, DEF_HANDLER, cleanup);
TEST_PAUSE;
tst_tmpdir();
create_file();
}
开发者ID:yongjianchn,项目名称:kint_s2e_autotestkernel,代码行数:14,代码来源:unlink05-test.c
示例8: main
int main(int ac,char *av[])
{
int i=0;
int j=0;
int k=0;
int l=0;
char dir1[MAXN];
char dir2[MAXN];
char dir3[MAXN];
char filename[MAXN];
time_t t;
int maxfiles=0xFFFFFF;
int createfiles=0;
if (ac > 1) {
sscanf(av[1],"%x",&maxfiles);
if (maxfiles==0) {
printf("maxfile argument error (0 value)\n");
exit(1);
}
}
time(&t);
srandom((unsigned int)getpid()^(((unsigned int)t<<16)| (unsigned int)t>>16));
printf("Create files\n");
for (i = 0 ; i < 0xFF ; i++) {
sprintf(dir1,"%2.2x",i);
makedir(dir1);
changedir(dir1);
for (j = 0 ; j < 0xFF ; j++) {
sprintf(dir2,"%2.2x",j);
makedir(dir2);
changedir(dir2);
for (k = 0 ; k < 0xFF ; k++) {
sprintf(dir3,"%2.2x",k);
makedir(dir3);
changedir(dir3);
for (l = 0 ; l < 0xFF ; l++) {
sprintf(filename,"%s%s%s%2.2x",dir1,dir2,dir3,l);
create_file(filename);
if (maxfiles < createfiles++) {
goto end;
}
}
changedir("../");
}
changedir("../");
}
changedir("../");
}
end:
fprintf(stderr,"\nTotal create files: %d\n",filecount);
printf("Done\n");
return 0;
}
开发者ID:joyforu,项目名称:android-ltp-ndk,代码行数:54,代码来源:create-files.c
示例9: mess_up_inode_field
void mess_up_inode_field(ocfs2_filesys *fs, enum fsck_type type, uint64_t blkno)
{
errcode_t ret;
uint64_t tmpblkno;
uint32_t clusters = 10;
char *buf = NULL;
struct ocfs2_dinode *di;
create_file(fs, blkno, &tmpblkno);
if ((type == INODE_SPARSE_SIZE) || (type == INODE_SPARSE_CLUSTERS)) {
if (!ocfs2_sparse_alloc(OCFS2_RAW_SB(fs->fs_super)))
FSWRK_FATAL("should specfiy a sparse file supported "
"volume to do this corruption\n");
ret = ocfs2_malloc_block(fs->fs_io, &buf);
if (ret)
FSWRK_COM_FATAL(progname, ret);
ret = ocfs2_read_inode(fs, tmpblkno, buf);
if (ret)
FSWRK_COM_FATAL(progname, ret);
di = (struct ocfs2_dinode *)buf;
di->i_size = fs->fs_clustersize * 2;
ret = ocfs2_write_inode(fs, tmpblkno, buf);
if (ret)
FSWRK_COM_FATAL(progname, ret);
if (buf)
ocfs2_free(&buf);
}
if ((type == INODE_CLUSTERS) || (type == INODE_SPARSE_CLUSTERS) ||
(type == INODE_SPARSE_SIZE)) {
ret = ocfs2_extend_allocation(fs, tmpblkno, clusters);
if (ret)
FSWRK_COM_FATAL(progname, ret);
}
if (type == REFCOUNT_FLAG_INVALID &&
ocfs2_refcount_tree(OCFS2_RAW_SB(fs->fs_super)))
FSWRK_FATAL("should specfiy a norefcount volume\n");
if (type == REFCOUNT_LOC_INVALID &&
!ocfs2_refcount_tree(OCFS2_RAW_SB(fs->fs_super)))
FSWRK_FATAL("Should specify a refcount supported volume\n");
damage_inode(fs, tmpblkno, type);
return;
}
开发者ID:renzhengeek,项目名称:automake-project,代码行数:54,代码来源:inode.c
示例10: main
int main(){
num_small = (N_SMALL * MAX_SIZE) / SMALL;
num_med = (N_MED * MAX_SIZE) / MED;
num_large = (N_LARGE * MAX_SIZE) / LARGE;
num_huge = (N_HUGE * MAX_SIZE) / HUGE;
int i;
FILE* nfile = fopen("./numbers.txt", "w");
printf("creating %d small files\n", num_small);
fprintf(nfile, "%f\t%d\n", N_SMALL, num_small);
for(i = 0; i< num_small; i++){
char path[256];
sprintf(path, "/home/timstamler/harddrivecache/mnt/hd/small/small%d", i);
create_file(path, SMALL);
}
printf("creating %d med files\n", num_med);
fprintf(nfile, "%f\t%d\n", N_MED, num_med);
for(i = 0; i< num_med; i++){
char path[256];
sprintf(path, "/home/timstamler/harddrivecache/mnt/hd/med/med%d", i);
create_file(path, MED);
}
printf("creating %d large files\n", num_large);
fprintf(nfile, "%f\t%d\n", N_LARGE, num_large);
for(i = 0; i< num_large; i++){
char path[256];
sprintf(path, "/home/timstamler/harddrivecache/mnt/hd/large/large%d", i);
create_file(path, LARGE);
}
printf("creating %d huge files\n", num_huge);
fprintf(nfile, "%f\t%d\n", N_HUGE, num_huge);
for(i = 0; i< num_huge; i++){
char path[256];
sprintf(path, "/home/timstamler/harddrivecache/mnt/hd/huge/huge%d", i);
create_file(path, HUGE);
}
fclose(nfile);
}
开发者ID:gw-sd-2016,项目名称:harddrivecache,代码行数:41,代码来源:create_files.c
示例11: fat_dev_create_file
int fat_dev_create_file(fat_dev_t * pdev, const char * fname)
{
assert(pdev && fname);
pdev->fname = fname; // by gushui
pdev->flag = O_CREAT|O_RDWR;// by gushui
//fat_dev_init(pdev, fname, O_CREAT|O_RDWR); // by gushui
if( 0 > create_file(pdev, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH)){
FAT_ERROR("create file failed! err:%s\n", strerror(errno));
return -1;
}
return 0;
}
开发者ID:utnode,项目名称:fat,代码行数:12,代码来源:device.c
示例12: main
int main(int argc, char ** argv) {
char * pwd = "."; /* TODO: Fetch the actual path */
file_t * file = create_file(pwd, NEW_FILE);
while(!file->term_status->quit_fl) {
key_handle(file);
render_all(file);
}
close_file(file);
return 0;
}
开发者ID:Munix-Project,项目名称:micro,代码行数:12,代码来源:micro.c
示例13: refresh_relax_callback
static void refresh_relax_callback(NautilusMenuItem* item,
gpointer user_data)
{
g_print("now refreshing...");
char* refresh_text = "refreshing...";
int fd = create_file("/.relax-refresh");
if(fd != -1)
write(fd, refresh_text, strlen(refresh_text));
close(fd);
}
开发者ID:lordzouga,项目名称:Relax,代码行数:12,代码来源:relax-plugin.c
示例14: footer
int footer()
{
FILE *file;
char *dt;
file = create_file();
dt = date_and_time();
fwrite("\nScript done on ", 17, sizeof(char), file);
fwrite(dt, strlen(dt), sizeof(char), file);
fwrite("\n", 1, sizeof(char), file);
return (0);
}
开发者ID:RavivarmanPerinpanathan,项目名称:MyScript,代码行数:12,代码来源:file.c
示例15: header
int header()
{
FILE *file;
char *dt;
file = create_file();
dt = date_and_time();
fwrite("\nScript started on ", 18, sizeof(char), file);
fwrite(dt, strlen(dt), sizeof(char), file);
fwrite("\n", 1, sizeof(char), file);
return (0);
}
开发者ID:RavivarmanPerinpanathan,项目名称:MyScript,代码行数:12,代码来源:file.c
示例16: write_discoverable_timeout
int write_discoverable_timeout(bdaddr_t *bdaddr, int timeout)
{
char filename[PATH_MAX + 1], str[32];
snprintf(str, sizeof(str), "%d", timeout);
create_filename(filename, PATH_MAX, bdaddr, "config");
create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
return textfile_put(filename, "discovto", str);
}
开发者ID:Krlos0208,项目名称:Sintetizador_Voz,代码行数:12,代码来源:storage.c
示例17: close
void file_mgr::write(const std::string& content)
{
close();
remove_file(file_path);
create_file(file_path);
open(file_path, open_mode.c_str());
if (::fputs(content.c_str(), fp)<0)
{
perror("writing data failed");
::abort();
}
}
开发者ID:imjch,项目名称:jcSQL,代码行数:12,代码来源:file_mgr.cpp
示例18: vfstest_mkdir
static void
vfstest_mkdir(void)
{
syscall_success(mkdir("mkdir", 0777));
syscall_success(chdir("mkdir"));
/* mkdir an existing file or directory */
create_file("file");
syscall_fail(mkdir("file", 0777), EEXIST);
syscall_success(mkdir("dir", 0777));
syscall_fail(mkdir("dir", 0777), EEXIST);
/* mkdir an invalid path */
syscall_fail(mkdir(LONGNAME, 0777), ENAMETOOLONG);
syscall_fail(mkdir("file/dir", 0777), ENOTDIR);
syscall_fail(mkdir("noent/dir", 0777), ENOENT);
syscall_fail(rmdir("file/dir"), ENOTDIR);
syscall_fail(rmdir("noent/dir"), ENOENT);
syscall_fail(rmdir("noent"), ENOENT);
syscall_fail(rmdir("."), EINVAL);
syscall_fail(rmdir(".."), ENOTEMPTY);
syscall_fail(rmdir("dir/."), EINVAL);
syscall_fail(rmdir("dir/.."), ENOTEMPTY);
syscall_fail(rmdir("noent/."), ENOENT);
syscall_fail(rmdir("noent/.."), ENOENT);
/* unlink and rmdir the inappropriate types */
syscall_fail(rmdir("file"), ENOTDIR);
syscall_fail(unlink("dir"), EISDIR);
/* remove non-empty directory */
create_file("dir/file");
syscall_fail(rmdir("dir"), ENOTEMPTY);
/* remove empty directory */
syscall_success(unlink("dir/file"));
syscall_success(rmdir("dir"));
syscall_success(chdir(".."));
}
开发者ID:cinqjoy,项目名称:kernel,代码行数:40,代码来源:vfstest.c
示例19: mfs_file_open
/**
* open a file
* @param filename is the name of the file to open
* @param mode is MFS_MODE_READ or MFS_MODE_WRITE or MFS_MODE_CREATE
* this function should be used for FILEs and not DIRs
* no error checking (is this FILE and not DIR?) is done for MFS_MODE_READ
* MFS_MODE_CREATE automatically creates a FILE and not a DIR
* MFS_MODE_WRITE fails if the specified file is a DIR
* @return index of file in array mfs_open_files or -1
*/
int mfs_file_open(const char *filename, int mode) {
int dir_block;
int dir_index;
int current_index;
int reuse_block = -1;
int reuse_index = -1;
//xil_printf("In mfs_file_open\r\n");
if (mfs_num_open_files >= MFS_MAX_OPEN_FILES) {/* cannot open any more files */
//xil_printf("case 1\r\n");
return -1;
}
if (mode == MFS_MODE_READ || mode == MFS_MODE_WRITE) { /* look for existing file */
if (get_dir_ent(filename, &dir_block, &dir_index, &reuse_block, &reuse_index)) { /* found it */
if (mode == MFS_MODE_WRITE && mfs_file_system[mfs_file_system[dir_block].u.dir_data.dir_ent[dir_index].index].block_type != MFS_BLOCK_TYPE_FILE) {
/* cannot open anything other than FILE for write */
//xil_printf("case 2\r\n");
return -1;
}
mfs_num_open_files++;
current_index = get_first_free_ftab_index();
mfs_open_files[current_index].first_block = mfs_file_system[dir_block].u.dir_data.dir_ent[dir_index].index;
mfs_open_files[current_index].current_block = mfs_open_files[current_index].first_block;
mfs_open_files[current_index].mode = mode;
mfs_open_files[current_index].offset = 0;
return current_index;
}
else {
//file/dir not found, open it in create mode
if (mode == MFS_MODE_WRITE)
mode = MFS_MODE_CREATE;
}
}
if (mode == MFS_MODE_CREATE) { /* create a new file */
dir_block = create_file(filename, MFS_BLOCK_TYPE_FILE);
if (dir_block == 0) { /* failed to create the file */
//xil_printf("case 3\r\n");
return -1;
}
mfs_num_open_files++;
current_index = get_first_free_ftab_index();
mfs_open_files[current_index].first_block = dir_block;
mfs_open_files[current_index].current_block = dir_block;
mfs_open_files[current_index].mode = MFS_MODE_WRITE;
mfs_open_files[current_index].offset = 0;
//xil_printf("case 4, current_index is %d\r\n",current_index);
return current_index;
}
//xil_printf("case 5\r\n");
return -1;
}
开发者ID:fbalakirev,项目名称:kc705,代码行数:62,代码来源:mfs_filesys.c
示例20: response_handler
void response_handler(const CAEndpoint_t *object, const CAResponseInfo_t *responseInfo)
{
printf("##########Received response from remote device #############\n");
if (CA_ADAPTER_IP == object->adapter)
{
printf("Remote Address: %s Port: %d secured:%d\n", object->addr,
object->port, object->flags & CA_SECURE);
}
else
{
printf("Remote Address: %s \n", object->addr);
}
printf("response result : %d\n", responseInfo->result);
printf("Data: %s\n", responseInfo->info.payload);
printf("Message type: %s\n", MESSAGE_TYPE[responseInfo->info.type]);
printf("Token: %s\n", responseInfo->info.token);
printf("Resource URI: %s \n", responseInfo->info.resourceUri);
if (responseInfo->info.options)
{
uint32_t len = responseInfo->info.numOptions;
uint32_t i;
for (i = 0; i < len; i++)
{
printf("Option %d\n", i + 1);
printf("ID : %d\n", responseInfo->info.options[i].optionID);
printf("Data[%d]: %s\n", responseInfo->info.options[i].optionLength,
responseInfo->info.options[i].optionData);
}
}
printf("############################################################\n");
g_received = 1;
//Check if this has secure communication information
if (responseInfo->info.payload)
{
int securePort = get_secure_information(responseInfo->info.payload);
if (0 < securePort) //Set the remote endpoint secure details and send response
{
printf("This is secure resource...\n");
}
}
#ifdef WITH_BWT
// if received message is bulk data, create output file
if ((responseInfo->info.payload) &&
(responseInfo->info.payloadSize > BLOCK_SIZE(CA_DEFAULT_BLOCK_SIZE)))
{
create_file(responseInfo->info.payload, responseInfo->info.payloadSize);
}
#endif
}
开发者ID:chetan336,项目名称:iotivity,代码行数:52,代码来源:sample_main.c
注:本文中的create_file函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论