自定义getMode --- 将mode_t 转换为相应的字符串

本文详细介绍了如何使用C语言自定义函数getMode,将mode_t类型转换为表示文件权限的字符串形式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

自定义getMode --- 将mode_t 转换为相应的字符串


/*
 * getMode.c
 *
 *  Created on: 2011-11-15
 *      Author: snape
 */

#include <stdio.h>
#include <fcntl.h>
#include <sys/types.h>
#include <string.h>

/*
 * mode_t 是一个八进制数
 * 0777 ---- 111 111 111
 * S_IRUSR 代表 100 000 000
 * mode_t & S_IRUSR 返回1 说明 具有该权限,返回0 说明不具有
 *
 */

int main(int argc, char **argv) {
	char *getMode(mode_t, char *);
	int mode = 0666;
	char buf[9];

	fprintf(stderr, "mode %d presents %s\n", mode, getMode(mode, buf));
	return 0;
}

char * getMode(mode_t mode, char *buf) {
	if (buf == NULL) {
		fprintf(stderr, "buf can't be NULL\n");
		return NULL;
	}

	memset(buf, '-', 9);

	if (mode & S_IRUSR)
		buf[0] = 'r';

	if (mode & S_IWUSR)
		buf[1] = 'w';
	if (mode & S_IXUSR)
		buf[2] = 'x';
	if (mode & S_IRGRP)
		buf[3] = 'r';
	if (mode & S_IWGRP)
		buf[4] = 'w';
	if (mode & S_IXGRP)
		buf[5] = 'x';
	if (mode & S_IROTH)
		buf[6] = 'r';
	if (mode & S_IWOTH)
		buf[7] = 'w';
	if (mode & S_IXOTH)
		buf[8] = 'x';

	buf[9] = NULL;
	return buf;
}


#ifndef netserver_h #define netserver_h #include "Arduino.h" #include "../AsyncWebServer/ESPAsyncWebServer.h" #include "AsyncUDP.h" enum requestType_e : uint8_t { PLAYLIST=1, STATION=2, STATIONNAME=3, ITEM=4, TITLE=5, VOLUME=6, NRSSI=7, BITRATE=8, MODE=9, EQUALIZER=10, BALANCE=11, PLAYLISTSAVED=12, GETMODE=13, GETINDEX=14, GETACTIVE=15, GETSYSTEM=16, GETSCREEN=17, GETTIMEZONE=18, GETWEATHER=19, GETCONTROLS=20, DSPON=21, SDPOS=22, SDLEN=23, SDSNUFFLE=24, SDINIT=25, GETPLAYERMODE=26, CHANGEMODE=27 }; enum import_e : uint8_t { IMDONE=0, IMPL=1, IMWIFI=2 }; const char emptyfs_html[] PROGMEM = R"( <!DOCTYPE html><html><head><meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=0.25"><meta charset="UTF-8"><link rel="icon" href="data:;base64,iVBORw0KGgo="><title>ёRadio - WEB Board Uploader</title><style>body{background-color:#000;color:#e3d25f;font-size:20px;} hr{margin:20px 0;border:0; border-top:#555 1px solid;} p{text-align:center;margin-bottom:10px;} section{max-width:500px; text-align:center;margin:0 auto 30px auto;} input[type=file]{color:#ccc;} input[type=file]::file-selector-button, input[type=submit]{border:2px solid #e3d25f;color:#000;padding:6px 16px;border-radius:25px;background-color:#e3d25f;margin:0 6px;cursor:pointer;} input[type=submit]{font-size:18px;text-transform:uppercase;padding:8px 26px;margin-top:10px;font-family:Times;} span{color:#ccc} .flex{display:flex;justify-content: space-around;margin-top:10px;} input[type=text],input[type=password]{width:170px;background:#272727;color:#e3d25f;padding:6px 12px;font-size:20px;border:#2d2d2d 1px solid;margin:4px 0 0 4px;border-radius:4px;outline:none;} @media screen and (max-width:480px) {section{zoom:0.7;-moz-transform:scale(0.7);}} </style></head><body> <section> <h2>ёRadio - WEB Board Uploader</h2> <hr /> <span>Select <u>ALL</u> files from <i>yoRadio/data/www/</i><br />and upload them using the form below</span> <hr /> <form action="/%ACTION%" method="post" enctype="multi
最新发布
03-25
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值