我注意到当我使用open+ 查询设备的大小时lseek,一切正常,但是当我stat使用设备时,我得到的是零,而不是实际的设备大小。该设备是干净的,没有任何文件系统,并且该设备的首字节以“ 1234567890ABC”之类的文本开头。怎么了?
代码:
#include <sys/stat.h>
#include <dirent.h>
bool
GetFileSize(const char* pPath, uint64_t& Size)
{
pPath = "/home/sw/.bashrc";
pPath = "/dev/sda";
struct stat buffer;
if (stat(pPath, &buffer))
{
printf("Failed to stat file. Error: %s. FilePath: %s\n", strerror(errno), pPath);
return false;
}
printf("File size by stat: %" PRIu64 " WTF?\n", buffer.st_size);
//
// Note: It's strange, but stat::st_size from the stat call is zero for devices
//
int File = open(pPath, O_RDONLY);
if (File < …Run Code Online (Sandbox Code Playgroud) 项目文件:
CONFIG -= qt
QMAKE_CXXFLAGS += -std=c++98
QMAKE_CXXFLAGS -= -std=c++11
QMAKE_CXXFLAGS -= -std=gnu++11
CONFIG -= c++11
Run Code Online (Sandbox Code Playgroud)
结果:
g++ -c -pipe -Wno-unused-parameter -Wno-unused-variable -Wno-unused-function -Wno-unused-but-set-variable -Wno-reorder -Wno-missing-field-initializers -std=c++98 -DDEBUG -g -std=gnu++11 -Wall -W -fPIC -DQT_QML_DEBUG -I../../qqq -I. -I../src/jsoncpp -I../lib -I../../../../Qt/5.9.1/gcc_64/mkspecs/linux-g++ -o ../build/debug/obj/TaskManager.o ../src/TaskManager.cpp
g++ -c -pipe -Wno-unused-parameter -Wno-unused-variable -Wno-unused-function -Wno-unused-but-set-variable -Wno-reorder -Wno-missing-field-initializers -std=c++98 -DDEBUG -g -std=gnu++11 -Wall -W -fPIC -DQT_QML_DEBUG -I../../qqq -I. -I../src/jsoncpp -I../lib -I../../../../Qt/5.9.1/gcc_64/mkspecs/linux-g++ -o ../build/debug/obj/Utils.o ../src/Utils.cpp
Run Code Online (Sandbox Code Playgroud)
如你所见,选项-std=gnu++11仍然存在(没有任何反应"QMAKE_CXXFLAGS -="/ "CONFIG -=").
Qt的:
Qt Creator 4.3.1 …Run Code Online (Sandbox Code Playgroud) 嗨同事我有代码(max_help_position是2000):
formatter_class=lambda prog: argparse.HelpFormatter(prog, max_help_position=2000)
parser = argparse.ArgumentParser(formatter_class=formatter_class)
subparsers = parser.add_subparsers(title="Commands", metavar="<command>")
cmd_parser = subparsers.add_parser('long_long_long_long_long_long_long',
help='- jksljdalkjda',
formatter_class=formatter_class)
args = parser.parse_args(['-h'])
print args
Run Code Online (Sandbox Code Playgroud)
我们有
optional arguments:
-h, --help show this help message and exit
Commands:
<command>
long_long_long_long_long_long_long
- jksljdalkjda
small - descr
Run Code Online (Sandbox Code Playgroud)
代替
optional arguments:
-h, --help show this help message and exit
Commands:
<command>
long_long_long_long_long_long_long - jksljdalkjda
small - descr
Run Code Online (Sandbox Code Playgroud)
你知道如何解决这个问题吗?
代码:
class MyFormatter(argparse.HelpFormatter):
def __init__(self, prog):
super(MyFormatter, self).__init__(prog, max_help_position=2000)
self._max_help_position = 2000
self._action_max_length += 4
formatter_class = MyFormatter …Run Code Online (Sandbox Code Playgroud)