function [STATUS, MESSAGE, MESSAGEID] = copyfile(srcIn, dstIn, flag)
%MATLAB Code Generation Library Function

%   Copyright 2023 The MathWorks, Inc.
%#codegen
narginchk(2,3)
throwError = (nargout == 0);

STATUS = false;
MESSAGE = coder.nullcopy(blanks(0));
MESSAGEID = coder.nullcopy(blanks(0));
coder.varsize('MESSAGEID');
coder.varsize('MESSAGE');

coder.extrinsic('copyfile');

if coder.internal.runs_in_matlab
    if nargin == 2
        if throwError
            copyfile(srcIn, dstIn);
        else
            [STATUS, MESSAGE, MESSAGEID] = copyfile(srcIn, dstIn);
        end
    else
        if throwError
            copyfile(srcIn, dstIn, flag)
        else
            [STATUS, MESSAGE, MESSAGEID] = copyfile(srcIn, dstIn, flag);
        end
    end
    return
end

coder.internal.assert(coder.areUnboundedVariableSizedArraysSupported, ...
    'Coder:toolbox:FuncNeedsDynamic', 'copyfile');
coder.internal.assert(coder.internal.isTextRow(srcIn), 'MATLAB:string');

src = convertStringsToChars(srcIn);
if isempty(src)
    [STATUS, MESSAGE, MESSAGEID] = ...
        coder.internal.iofun.errorHandler.setOrThrowError(coder.internal.iofun.errorHandler.EILLEGAL, ...
        throwError);
    return
end
for i = 1:numel(src)
    coder.internal.assert(src(i) ~= char(0), 'MATLAB:FileManip:NullCharacterInName');
end

isForce = false;
if nargin == 1
    dst = pwd;
elseif nargin >= 2
    coder.internal.assert(coder.internal.isTextRow(dstIn), 'MATLAB:string');
    dst = convertStringsToChars(dstIn);
    if isempty(dst)
        [STATUS, MESSAGE, MESSAGEID] = ...
            coder.internal.iofun.errorHandler.setOrThrowError(coder.internal.iofun.errorHandler.EILLEGAL, ...
            throwError);
        return
    end
    for i = 1:numel(dst)
        coder.internal.assert(dst(i) ~= char(0), 'MATLAB:FileManip:NullCharacterInName');
    end
end
if nargin == 3
    coder.internal.assert(coder.internal.isTextRow(flag), 'MATLAB:string');
    isForce = coder.internal.iofun.parseFlag(flag);
end

% Call common process function
[~, ERRCODE] = processMoveCopy(src, dst, isForce, 'c');

[STATUS, MESSAGE, MESSAGEID] = coder.internal.iofun.errorHandler.setOrThrowError(ERRCODE, throwError, isForce);